<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>生产实习记录 | Mox的笔记库</title><meta name="keywords" content="Working"><meta name="author" content="MocusEZ"><meta name="copyright" content="MocusEZ"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="很普通的生产实习记录">
<meta property="og:type" content="article">
<meta property="og:title" content="生产实习记录">
<meta property="og:url" content="https://www.mocusez.site/posts/5862.html">
<meta property="og:site_name" content="Mox的笔记库">
<meta property="og:description" content="很普通的生产实习记录">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/09/02/pPBH058.png">
<meta property="article:published_time" content="2023-09-02T13:51:00.000Z">
<meta property="article:modified_time" content="2023-09-02T13:51:00.000Z">
<meta property="article:author" content="MocusEZ">
<meta property="article:tag" content="Working">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/09/02/pPBH058.png"><link rel="shortcut icon" href="/img/title.jpg"><link rel="canonical" href="https://www.mocusez.site/posts/5862"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?c85c9eaebc158345532b86397a6dded9";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '生产实习记录',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-09-02 21:51:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/atom.xml" title="Mox的笔记库" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">61</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链&amp;私人收藏</span></a></div><div class="menus_item"><a class="site-page" href="/board/"><i class="fa-fw fas fa-user"></i><span> 留言板</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s1.ax1x.com/2023/09/02/pPBH058.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Mox的笔记库</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链&amp;私人收藏</span></a></div><div class="menus_item"><a class="site-page" href="/board/"><i class="fa-fw fas fa-user"></i><span> 留言板</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">生产实习记录</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-09-02T13:51:00.000Z" title="发表于 2023-09-02 21:51:00">2023-09-02</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-09-02T13:51:00.000Z" title="更新于 2023-09-02 21:51:00">2023-09-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%97%A5%E5%B8%B8%E7%AC%94%E8%AE%B0/">日常笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="生产实习记录"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="生产实习记录"><a href="#生产实习记录" class="headerlink" title="生产实习记录"></a>生产实习记录</h1><p>2023年6月学校安排去中软国际下属的一家公司进行生产实习。</p>
<p>个人觉得这次实习还是蛮有意思的：一个Hadoop开发项目。但首先于时间和参与项目的队友编程能力，在一点遗憾中结束了这次生产实习。</p>
<p>现在记录下当时的踩坑记录</p>
<h1 id="Hadoop学习"><a href="#Hadoop学习" class="headerlink" title="Hadoop学习"></a>Hadoop学习</h1><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/weixin_43986204/article/details/90210010">Windows环境下hadoop安装和配置详细步骤</a></p>
<p>在Windows下配置Hadoop环境的注意事项</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">将C:\PROGRA~1\Java\jdk1.7.0_67 改为 D:\Softwares\jdk1.8（在环境变量设置中JAVA_HOME的值）(如果路径中有“Program Files”，则将Program Files改为 PROGRA~1）</span><br></pre></td></tr></table></figure>

<p>看完教程后嫌麻烦，还是VMware装三台CentOS 7虚拟机完成Hadoop集群搭建。</p>
<p>搭建完成后，使用jps命令查看运行情况</p>
<h2 id="Idea-Hadoop配置"><a href="#Idea-Hadoop配置" class="headerlink" title="Idea Hadoop配置"></a>Idea Hadoop配置</h2><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_42185397/article/details/115206308">Windows：IDEA配置Maven、Hadoop详细教程</a></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop namenode -format</span><br></pre></td></tr></table></figure>



<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">export</span> HADOOP_HOME=/root/hadoop-2.10.2</span><br><span class="line"><span class="built_in">export</span> PATH=<span class="variable">$PATH</span>:<span class="variable">$HADOOP_HOME</span>/bin:<span class="variable">$HADOOP_HOME</span>/sbin</span><br></pre></td></tr></table></figure>



<h2 id="HDFS指令"><a href="#HDFS指令" class="headerlink" title="HDFS指令"></a>HDFS指令</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -<span class="built_in">ls</span> /test</span><br></pre></td></tr></table></figure>

<p>等价于</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -<span class="built_in">ls</span> hdfs:///test</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -mkdir</span><br></pre></td></tr></table></figure>

<p>直接访问本机文件系统</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -<span class="built_in">ls</span> file:///root</span><br></pre></td></tr></table></figure>

<p>下面的操作基本就和Linux的Shell命令差不多，CSDN和博客园哪些那些记录的更加详细</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -mkdir</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -touchz</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -cat</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -cp file:///root/1.txt /test/</span><br><span class="line">hadoop fs -mv file:///root/1.txt /test/</span><br><span class="line">hadoop fs -rm</span><br><span class="line">hadoop fs -puts</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hadoop fs -appendToFile  &lt;local&gt; &lt;remote&gt;</span><br><span class="line">hadoop fs -put /root/1.txt hdfs:///test/2.txt</span><br><span class="line">hadoop fs -get hdfs:///test/2.txt files:///root/</span><br></pre></td></tr></table></figure>

<h2 id="MapReduce基本概念"><a href="#MapReduce基本概念" class="headerlink" title="MapReduce基本概念"></a>MapReduce基本概念</h2><p>map：分开计算</p>
<p>shuffle：将map结果分组，排序整理</p>
<p>reduce：统计</p>
<p>shuffle &#x3D; map.shuffle + reduce.shuffle</p>
<p>reduce的shuffle不需要编程</p>
<h1 id="MapReduce操作"><a href="#MapReduce操作" class="headerlink" title="MapReduce操作"></a>MapReduce操作</h1><h2 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h2><h3 id="数字型"><a href="#数字型" class="headerlink" title="数字型"></a>数字型</h3><p>框架需要对key和value的类(classes)进行序列化操作，因此，这些类需要实现<strong>Writable接口</strong>。</p>
<p>另外，为了方便框架执行排序操作，key类必须实现WritableComparable接口。Hadoop定义的数字类型有BooleanWritable，ByteWritable， IntWritable， LongWritable，FloatWritable，DoubleWritable 分别对应：boolean，byte，int, long, float, double 基本类型。这些类中，都有一个get()方法得到基础类型的值，它们的构造器参数可以是其对应的基础类型的值。如：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">IntWritable value = new IntWritable(123);</span><br><span class="line">int data = value.get();</span><br></pre></td></tr></table></figure>

<h3 id="字符型"><a href="#字符型" class="headerlink" title="字符型"></a>字符型</h3><p>Text 是Hadoop定义的字符类型，对应 String。如：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Text</span> <span class="variable">value</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Text</span>(<span class="string">&quot;abc&quot;</span>);    <span class="comment">//创建Text类型数据</span></span><br><span class="line"><span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> value.toString();       <span class="comment">//将Text类型数据转换为String</span></span><br></pre></td></tr></table></figure>

<h2 id="Example"><a href="#Example" class="headerlink" title="Example"></a>Example</h2><p>需要一个Mapper和Reducer</p>
<h3 id="Mapper"><a href="#Mapper" class="headerlink" title="Mapper"></a>Mapper</h3><p>以键值对的方式读取</p>
<p>extends Mapper&lt;LongWritable, Text, Text, IntWritable&gt;</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Test</span> &#123;</span><br><span class="line">	</span><br><span class="line">	<span class="comment">/**</span></span><br><span class="line"><span class="comment">	 * static 			必不可少</span></span><br><span class="line"><span class="comment">	 * LongWritable  	数据集文件的行号，输入参数</span></span><br><span class="line"><span class="comment">	 * Text   		数据集文件一行的内容，输入参数</span></span><br><span class="line"><span class="comment">	 * Text  			map输出的key类型，输出参数</span></span><br><span class="line"><span class="comment">	 * IntWritable  	map输出的value类型，输出参数</span></span><br><span class="line"><span class="comment">	 *</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Mappers</span> <span class="keyword">extends</span> <span class="title class_">Mapper</span>&lt;LongWritable, Text, Text, IntWritable&gt;&#123;</span><br><span class="line"></span><br><span class="line">		<span class="comment">/**</span></span><br><span class="line"><span class="comment">		 * key	 与 Mapper&lt;LongWritable, Text, Text, IntWritable&gt;中的第一个参数类型一致</span></span><br><span class="line"><span class="comment">		 * value  与 Mapper&lt;LongWritable, Text, Text, IntWritable&gt;中的第二个参数类型一致	</span></span><br><span class="line"><span class="comment">		 *  如果数据集中有10行数据，该方法将被调用10次</span></span><br><span class="line"><span class="comment">		 */</span></span><br><span class="line">		<span class="meta">@Override</span></span><br><span class="line">		<span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">map</span><span class="params">(LongWritable key, Text value, Context context)</span></span><br><span class="line">				<span class="keyword">throws</span> IOException, InterruptedException &#123;</span><br><span class="line">			<span class="comment">//读取文件一行的内容，将其转换为字符串，文件的编码一定要是utf-8。</span></span><br><span class="line">			<span class="type">String</span> <span class="variable">text</span> <span class="operator">=</span> value.toString();   </span><br><span class="line">			System.out.println(<span class="string">&quot;value=&quot;</span>+text);</span><br><span class="line">			</span><br><span class="line">			String[] fields = text.split(<span class="string">&quot;,&quot;</span>);  <span class="comment">//分隔成需要的字段</span></span><br><span class="line">			</span><br><span class="line">			<span class="comment">//write方法中的第一参数与Mapper&lt;LongWritable, Text, Text, IntWritable&gt;中的第三个参数类型一致</span></span><br><span class="line">			<span class="comment">//write方法中的第二参数与Mapper&lt;LongWritable, Text, Text, IntWritable&gt;中的第四个参数类型一致</span></span><br><span class="line">			<span class="comment">//将 key/vlaue 对 写入map的输出文件中, ,输出文件名为part-r-00000</span></span><br><span class="line">			context.write(<span class="keyword">new</span> <span class="title class_">Text</span>(fields[<span class="number">7</span>].trim()), <span class="keyword">new</span> <span class="title class_">IntWritable</span>(<span class="number">1</span>));</span><br><span class="line">		&#125;		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="Reducer"><a href="#Reducer" class="headerlink" title="Reducer"></a>Reducer</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">	 * static 			必不可少</span></span><br><span class="line"><span class="comment">	 * Text   		map输出文件中的key类型，输入参数</span></span><br><span class="line"><span class="comment">	 * IntWritable    map输出文件中的value类型，输入参数</span></span><br><span class="line"><span class="comment">	 * Text  			reduce输出的key类型，输出参数</span></span><br><span class="line"><span class="comment">	 * IntWritable  	reduce输出的value类型，输出参数</span></span><br><span class="line"><span class="comment">	 * 该方法只被调用一次</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Reducers</span> <span class="keyword">extends</span> <span class="title class_">Reducer</span>&lt;Text, IntWritable, Text, IntWritable&gt;&#123;</span><br><span class="line"></span><br><span class="line">		<span class="comment">/**</span></span><br><span class="line"><span class="comment">		 * values 存放的是key对应的所有value的列表，来自于map的输出</span></span><br><span class="line"><span class="comment">		 */</span></span><br><span class="line">		<span class="meta">@Override</span></span><br><span class="line">		<span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">reduce</span><span class="params">(Text key, Iterable&lt;IntWritable&gt; values, 	Context context)</span></span><br><span class="line">				<span class="keyword">throws</span> IOException, InterruptedException &#123;</span><br><span class="line">			<span class="type">int</span> <span class="variable">count</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line">			<span class="keyword">for</span>(IntWritable p : values)&#123;</span><br><span class="line">				count ++;				</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="comment">//将 key/vlaue 对 写入到输出文件,输出文件名为part-r-00000</span></span><br><span class="line">			context.write(key, <span class="keyword">new</span> <span class="title class_">IntWritable</span>(count));			</span><br><span class="line">		&#125;		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="Job实现"><a href="#Job实现" class="headerlink" title="Job实现"></a>Job实现</h3><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_43674360/article/details/109447995">hadoop案例:自定义inputformat</a></p>
<p>在Hadoop 2中，MapReduce是一种分布式处理框架，用于处理大规模数据集的计算任务。一个MapReduce作业由多个Map阶段和一个Reduce阶段组成，它们可以在集群中并行执行。</p>
<p><code>org.apache.hadoop.mapreduce.Job</code>类是Hadoop中表示一个MapReduce作业的主要类。以下是关于Job类的一些重要方法和概念：</p>
<ol>
<li>创建Job对象：使用<code>Job.getInstance()</code>方法创建一个Job对象，并指定所在的集群和配置。</li>
<li>设置输入和输出路径：使用<code>Job.setInputFormatClass()</code>方法指定输入文件的格式以及用<code>FileInputFormat</code>设置输入路径，使用<code>Job.setOutputFormatClass()</code>方法指定输出文件的格式以及用<code>FileOutputFormat</code>设置输出路径。</li>
<li>设置Mapper和Reducer类：使用<code>Job.setMapperClass()</code>和<code>Job.setReducerClass()</code>方法设置自定义的Mapper和Reducer类。</li>
<li>设置Mapper和Reducer的输出键值对类型：使用<code>Job.setMapOutputKeyClass()</code>和<code>Job.setMapOutputValueClass()</code>方法设置Mapper的输出键值对类型，使用<code>Job.setOutputKeyClass()</code>和<code>Job.setOutputValueClass()</code>方法设置Reducer的输出键值对类型。</li>
<li>设置要使用的资源文件和库文件：使用<code>Job.addFileToClassPath()</code>方法添加要使用的资源文件、<code>Job.addArchiveToClassPath()</code>方法添加要使用的压缩库文件。</li>
<li>提交作业并等待完成：使用<code>Job.waitForCompletion()</code>方法提交作业，并等待作业完成。</li>
</ol>
<p>在 Hadoop 中，<code>job.setInputFormatClass()</code> 用于指定输入数据的格式。参数常见如下：</p>
<ol>
<li><code>TextInputFormat</code>：将输入文件视为逐行文本文件。</li>
<li><code>KeyValueInputFormat</code>：将输入文件视为键值对（key-value）文件。</li>
<li><code>SequenceFileInputFormat</code>：将输入文件视为序列文件，其中包含键值对数据。</li>
<li><code>CombineTextInputFormat</code>：类似于 <code>TextInputFormat</code>，但在处理大型文本文件时能够更好地利用 Hadoop 的 <code>InputSplit</code> 功能。</li>
<li><code>NLineInputFormat</code>：根据指定的行数将输入文件划分为 <code>InputSplit</code>。</li>
<li><code>CustomInputFormat</code>：根据用户的需求自定义的输入格式。</li>
</ol>
<p>这只是一些常见的输入格式类，实际上还可以根据需要自定义输入格式类来满足特定的需求。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> org.example;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.conf.Configured;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.fs.Path;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.io.LongWritable;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.io.Text;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.mapreduce.Job;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.mapreduce.lib.input.TextInputFormat;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.util.Tool;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WordCountJob</span> <span class="keyword">extends</span> <span class="title class_">Configured</span> <span class="keyword">implements</span> <span class="title class_">Tool</span> &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">run</span><span class="params">(String[] strings)</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        <span class="type">Job</span> <span class="variable">job</span> <span class="operator">=</span> Job.getInstance(<span class="built_in">super</span>.getConf(), <span class="string">&quot;WordCount_Job&quot;</span>);</span><br><span class="line"></span><br><span class="line">        job.setInputFormatClass(TextInputFormat.class);</span><br><span class="line">        TextInputFormat.addInputPath(job, <span class="keyword">new</span> <span class="title class_">Path</span>(<span class="string">&quot;hdfs:///WordCount.input&quot;</span>));</span><br><span class="line"></span><br><span class="line">        job.setMapperClass(WordCountMapper.class);</span><br><span class="line">        job.setMapOutputKeyClass(Text.class);</span><br><span class="line">        job.setMapOutputValueClass(LongWritable.class);</span><br><span class="line"></span><br><span class="line">        job.setReducerClass(WordCountReducer.class);</span><br><span class="line">        job.setOutputKeyClass(Text.class);</span><br><span class="line">        job.setOutputValueClass(LongWritable.class);</span><br><span class="line">        job.setOutputFormatClass(TextOutputFormat.class);</span><br><span class="line"></span><br><span class="line">        TextOutputFormat.setOutputPath(job, <span class="keyword">new</span></span><br><span class="line">                <span class="title class_">Path</span>(<span class="string">&quot;hdfs:///WordCount_Output&quot;</span>));</span><br><span class="line">        <span class="type">boolean</span> <span class="variable">success</span> <span class="operator">=</span> job.waitForCompletion(<span class="literal">true</span>);</span><br><span class="line">        <span class="keyword">return</span> success ? <span class="number">0</span> : <span class="number">1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="执行程序"><a href="#执行程序" class="headerlink" title="执行程序"></a>执行程序</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hadoop jar *****.jar your.package.name.YourMainClas</span><br></pre></td></tr></table></figure>



<h1 id="Hive操作"><a href="#Hive操作" class="headerlink" title="Hive操作"></a>Hive操作</h1><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_40692666/article/details/105079106">CentOS7 上 Hive安装&amp;配置 超全过程</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://zhuanlan.zhihu.com/p/53685086">对Hadoop和Hive的初步认识</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hive.apache.org/">Hive官网</a></p>
<p>Hive数据仓库</p>
<p>数据仓库主要面对OLAP（联机分析处理），侧重决策分析。</p>
<p><strong>Hive是依赖于Hadoop存在的，其次因为MapReduce语法较复杂，Hive可以将较简单的SQL语句转化成MapReduce进行计算！！！</strong></p>
<p>[<img src="https://s1.ax1x.com/2023/09/02/pPBH058.png" alt="pPBH058.png">]</p>
<p>Mahout提供一些可扩展的机器学习领域的经典算法实现，用于创建商务智能（BI）应用程序</p>
<h2 id="Beeline"><a href="#Beeline" class="headerlink" title="Beeline"></a>Beeline</h2><p>Hive客户端工具后续将使用Beeline 替代HiveCLI ，并且后续版本也会废弃掉HiveCLI 客户端工具,Beeline是 Hive 0.11版本引入的新命令行客户端工具,它是基于SQLLine CLI的JDBC客户</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/tktttt/article/details/110088179">hive之beeline连接与操作</a></p>
<h2 id="数据初始化"><a href="#数据初始化" class="headerlink" title="数据初始化"></a>数据初始化</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">schematool -initSchema -dbType mysql</span><br></pre></td></tr></table></figure>

<h2 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h2><p>两者，要么挂screen，要么挂hiveserver2</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hive --service metastore</span><br><span class="line">hive --service hiveserver2</span><br></pre></td></tr></table></figure>

<p>Hive获取Mysql<a target="_blank" rel="noopener external nofollow noreferrer" href="https://so.csdn.net/so/search?q=%E5%85%83%E6%95%B0%E6%8D%AE&spm=1001.2101.3001.7020">元数据</a>的两种方式：<br>①Hive直连MySQL获取元数据<br> 启动方式：只需直接启动Hive客户端，即可连接<br>②Hive先连接Metastore服务，再通过 Metastore服务连接MySQL获取元数据</p>
<p>​	hive比较特殊，它既是自己的客户端，又是服务端。Hive充当客户端（是HDFS的客户端也是Metastore的客户端,也是Hive的客户端）又充当服务端（因为有Metastore服务和Hiveserver2服务配置）<br>​	因为在实际生产环境下，可能有多台Hive客户端（比如有：103、104、105三台机器），MySQL的 IP地址对外不暴露，只暴露给其中一台（假如暴露给103这台机器），那么其他客户端怎么连接呢？那么就需要在暴露的那台机器上启动Metastore服务，其他Hive客户端连接这个Metastore服务，进而达到连接Mysql获取元数据的目的。</p>
<p>hive是hadoop的客户端，同时hive本身也有客户端，Hiveserver2的beeline连接方式实际是Hive与Hive之间的服务端与客户端通过JDBC连接的方式</p>
<h2 id="hiveserver2"><a href="#hiveserver2" class="headerlink" title="hiveserver2"></a>hiveserver2</h2><p>HiveServer 是 Hive 的一个组件，它是 Hive 提供给外部客户端连接和交互的接口。HiveServer 允许用户通过各种编程语言（如 Java、Python、PHP 等）或工具（如 JDBC、ODBC 驱动）连接到 Hive，并执行 Hive 查询、操作数据等操作。</p>
<p>HiveServer 提供了两种不同的实现方式：</p>
<ol>
<li><p>HiveServer1：HiveServer1 是旧版本的 HiveServer，它使用 Thrift 作为通信协议。HiveServer1 支持 Hive CLI 和其他的 Thrift 客户端连接，但不支持 JDBC 和 ODBC 连接。</p>
</li>
<li><p>HiveServer2：HiveServer2 是新版本的 HiveServer，它使用了更高级的 Thrift 通信协议，并提供了更多的功能和可扩展性。HiveServer2 支持 JDBC 和 ODBC 连接，可以通过各种编程语言和工具连接到 Hive 进行查询和操作。</p>
</li>
</ol>
<p>使用 HiveServer，你可以将 Hive 集成到你的应用程序中，通过编程方式连接到 Hive 并执行 Hive 查询。这样，你可以使用 Hive 的强大的数据处理能力和 SQL 查询语言来处理大规模数据集。</p>
<p>在配置和使用 HiveServer 时，你需要指定 HiveServer 的监听地址、端口号、认证方式等配置，并确保 HiveServer 进程正在运行。一旦 HiveServer 运行起来，你就可以通过指定的连接方式和参数来连接到 HiveServer，并执行查询和操作。</p>
<h2 id="Metastore"><a href="#Metastore" class="headerlink" title="Metastore"></a>Metastore</h2><p>Hive 的 Metastore（元数据存储）是 Hive 的一个重要组件，它负责管理和存储 Hive 的元数据信息。元数据是描述数据的数据，它包含了表、分区、列、数据类型、表结构、表之间的关系等信息。</p>
<p>Hive 的 Metastore 将元数据存储在持久化的存储介质中，通常是一个关系型数据库（如 MySQL、PostgreSQL 等）。Metastore 将 Hive 的元数据信息组织成一个层次结构，包含数据库（database）、表（table）、分区（partition）等对象。</p>
<p>Metastore 提供了一组 API 和命令，用于管理和操作 Hive 的元数据。它负责处理表的创建、修改、删除，以及对表的元数据进行查询、检索等操作。Metastore 还支持表的分区管理，可以将表分成多个分区，每个分区可以根据不同的条件进行划分和管理。</p>
<p>Metastore 的主要功能包括：</p>
<ol>
<li><p>元数据存储：Metastore 将 Hive 的元数据信息存储在持久化的存储介质中，以便在需要时进行检索和查询。</p>
</li>
<li><p>元数据管理：Metastore 提供了 API 和命令，用于管理和操作 Hive 的元数据。它可以创建、修改、删除表，管理分区等操作。</p>
</li>
<li><p>元数据查询：Metastore 提供了查询接口，可以根据条件查询表的元数据信息，如表的结构、列的属性等。</p>
</li>
<li><p>分区管理：Metastore 支持表的分区管理，可以将表分成多个分区，每个分区可以根据不同的条件进行划分和管理。</p>
</li>
</ol>
<p>通过 Metastore，Hive 可以方便地管理和操作元数据信息，使得用户可以使用类似于 SQL 的语法来查询和操作大规模数据集。同时，Metastore 的使用还提高了 Hive 查询的性能，因为 Hive 可以利用元数据信息来进行查询优化和执行计划的生成。</p>
<h2 id="HiveQL"><a href="#HiveQL" class="headerlink" title="HiveQL"></a>HiveQL</h2><p>Hadoop Hive（简称Hive）是一个基于Hadoop的数据仓库工具，它提供了一个类似于SQL的查询语言（HiveQL），用于处理和分析大规模的结构化和半结构化数据。</p>
<p>Hive 是为了方便数据分析人员使用 SQL 类似的查询语言来处理大规模数据而设计的，它将 SQL 查询转换为 Hadoop MapReduce 任务来执行。因此，Hive 可以让非程序员也能够使用 SQL 类似的语法来查询和分析大规模数据，而无需编写复杂的 MapReduce 程序。</p>
<p>Hive 使用 HiveQL（Hive Query Language）作为查询语言，HiveQL 类似于 SQL，但在语法和功能上有一些差异。HiveQL 支持常见的 SQL 操作，如 SELECT、JOIN、GROUP BY、WHERE 等，同时还支持用户自定义函数（UDF）、分区表、存储格式等特性。</p>
<p>Hive 的底层数据存储在 Hadoop 分布式文件系统（HDFS）中，并通过 Hive 的元数据存储（Metastore）来管理和查询数据的元数据信息。Hive 将数据存储为表的形式，表可以分成多个分区，每个分区可以根据不同的条件进行划分和管理。</p>
<p>使用 Hive，你可以通过 HiveQL 查询和分析大规模数据，利用 Hadoop 的并行计算能力来加速数据处理。Hive 还提供了丰富的内置函数和扩展功能，使得数据分析更加灵活和高效。</p>
<p>需要注意的是，Hive 不适用于实时数据处理和低延迟查询，因为它是基于批处理的模型。如果需要实时数据处理，可以考虑使用类似于 Apache Spark 的流式处理框架。</p>
<p>Hive中的表不支持<strong>直接定义主键约束</strong>，因为Hive是一个基于Hadoop的数据仓库系统，它的主要目标是提供大规模数据存储和查询的功能，而<strong>不是提供完整的事务支持</strong>。</p>
<h3 id="表创建测试"><a href="#表创建测试" class="headerlink" title="表创建测试"></a>表创建测试</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> test_table (</span><br><span class="line">  id <span class="type">INT</span>,</span><br><span class="line">  name STRING</span><br><span class="line">)</span><br><span class="line"><span class="type">ROW</span> FORMAT DELIMITED FIELDS TERMINATED <span class="keyword">BY</span> <span class="string">&#x27;,&#x27;</span></span><br><span class="line"><span class="type">ROW</span> FORMAT DELIMITED</span><br><span class="line">FIELDS TERMINATED <span class="keyword">BY</span> <span class="string">&#x27;,&#x27;</span></span><br><span class="line">STORED <span class="keyword">AS</span> TEXTFILE;</span><br></pre></td></tr></table></figure>

<p>default创建的表，会直接放在warehouse下边</p>
<p>在创建Hive表时，默认行分隔符”^A”，列分隔符”\n”，这两项也是可以设置的。在实际开发中，一般默认使用默认的分隔符，当然有些场景下也会自定义分隔符。</p>
<p>数据行可能是单个文件（甚至可以以文本形式打开）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">ROW</span> FORMAT DELIMITED FIELDS TERMINATED <span class="keyword">BY</span> <span class="string">&#x27;\t&#x27;</span></span><br><span class="line"><span class="type">ROW</span> FORMAT DELIMITED FIELDS TERMINATED <span class="keyword">BY</span> <span class="string">&#x27;,&#x27;</span></span><br></pre></td></tr></table></figure>

<p>查看表的数据属性</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">desc</span> table_3</span><br></pre></td></tr></table></figure>

<p>创建新表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> table_3 <span class="keyword">as</span> <span class="keyword">select</span> name <span class="keyword">from</span> test_table </span><br></pre></td></tr></table></figure>

<h3 id="删库"><a href="#删库" class="headerlink" title="删库"></a>删库</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">drop database db_1</span><br></pre></td></tr></table></figure>

<h3 id="查看表"><a href="#查看表" class="headerlink" title="查看表"></a>查看表</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">from</span> test_table limit <span class="number">2</span></span><br></pre></td></tr></table></figure>

<h3 id="DML处理"><a href="#DML处理" class="headerlink" title="DML处理"></a>DML处理</h3><p>数据源导入</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LOAD DATA <span class="keyword">LOCAL</span> INPATH <span class="string">&#x27;/root/abcd.txt&#x27;</span> <span class="keyword">into</span> db.table_2</span><br></pre></td></tr></table></figure>

<p>将文件中的数据导入（Load）到 Hive 表中</p>
<p>直接insert</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> test_table <span class="keyword">VALUES</span> (<span class="number">1</span>, <span class="string">&#x27;John&#x27;</span>);</span><br></pre></td></tr></table></figure>



<h3 id="连接JDBC"><a href="#连接JDBC" class="headerlink" title="连接JDBC"></a>连接JDBC</h3><p>与springboot貌似有依赖冲突，可能还有hive-common</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.hive<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>hive-jdbc<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.1.3<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">exclusions</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>*<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>*<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">exclusions</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h3 id="select操作"><a href="#select操作" class="headerlink" title="select操作"></a>select操作</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> concat(&quot;abcd&quot;,&quot;efgh&quot;)</span><br><span class="line"><span class="keyword">select</span> concat_ws(&quot;.&quot;,&quot;com&quot;,&quot;baidu&quot;,&quot;tieba&quot;)</span><br><span class="line"><span class="keyword">select</span> substr(&quot;apple&quot;,<span class="number">-4</span>)</span><br><span class="line"><span class="keyword">select</span> split(&quot;golden states&quot;,&quot; &quot;)</span><br><span class="line"><span class="keyword">select</span> <span class="built_in">CURRENT_DATE</span>() </span><br><span class="line"><span class="keyword">select</span> unix_timestamp()</span><br><span class="line"><span class="keyword">select</span> unix_timestamp(&quot;2030-08-08 08:00:00&quot;)</span><br><span class="line"><span class="keyword">select</span> from_unixtime()</span><br><span class="line"><span class="keyword">select</span> rand()</span><br></pre></td></tr></table></figure>



<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> nv1(<span class="keyword">NULL</span>, &quot;abcd&quot;);</span><br></pre></td></tr></table></figure>

<p>NVL函数的功能是实现空值的转换，根据第一个表达式的值是否为空值来返回相应的列名或表达式，主要用于对数据列上的空值进行处理，语法格式如</p>
<h3 id="Hive实现WordCount"><a href="#Hive实现WordCount" class="headerlink" title="Hive实现WordCount"></a>Hive实现WordCount</h3><p>在Hive中实现WordCount算法可以通过以下步骤：</p>
<ol>
<li>创建一个包含文本数据的表：首先，使用Hive创建一个包含文本数据的表，其中每一行表示一个文本文件中的内容，每个单词用空格或其他分隔符分隔。你可以使用如下的Hive语句创建表：</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> text_data (line STRING);</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>导入文本数据：使用Hive的<code>LOAD DATA</code>命令将文本数据导入到上述的<code>text_data</code>表中。假设数据文件<code>data.txt</code>包含文本数据，可以使用如下命令导入数据：</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LOAD DATA INPATH <span class="string">&#x27;/data.txt&#x27;</span> <span class="keyword">INTO</span> <span class="keyword">TABLE</span> text_data;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>编写WordCount查询：使用Hive的查询语法编写WordCount查询。以下是一个示例查询，可以计算每个单词的出现次数：</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> word, <span class="built_in">COUNT</span>(<span class="operator">*</span>) <span class="keyword">AS</span> count</span><br><span class="line"><span class="keyword">FROM</span> (</span><br><span class="line">  <span class="keyword">SELECT</span> explode(split(line, <span class="string">&#x27;,&#x27;</span>)) <span class="keyword">AS</span> word</span><br><span class="line">  <span class="keyword">FROM</span> text_data</span><br><span class="line">) t</span><br><span class="line"><span class="keyword">WHERE</span> word <span class="operator">!=</span> <span class="string">&#x27;&#x27;</span></span><br><span class="line"><span class="keyword">GROUP</span> <span class="keyword">BY</span> word</span><br><span class="line"><span class="keyword">ORDER</span> <span class="keyword">BY</span> count <span class="keyword">DESC</span>;</span><br></pre></td></tr></table></figure>

<p>上述查询中，首先使用<code>split</code>函数将每一行的内容拆分成单词，并使用<code>explode</code>函数将拆分后的单词展开成多个行。然后，将结果进行分组、计数和排序，以得到每个单词的出现次数。</p>
<ol start="4">
<li>运行查询：在Hive中运行上述查询，并查看结果。你可以使用Hive的命令行界面或其他Hive客户端运行查询。</li>
</ol>
<p>请注意，为了更准确地进行WordCount，你可能需要进行一些文本处理和清洗操作，如删除标点符号、转换为小写等。你可以根据具体需求进行适当的修改。</p>
<h3 id="貌似Druid可以统一MySQL与Hive"><a href="#貌似Druid可以统一MySQL与Hive" class="headerlink" title="貌似Druid可以统一MySQL与Hive"></a>貌似Druid可以统一MySQL与Hive</h3><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/wsjslient/article/details/115980947">使用MyBatis读取Hive数据并写入MySQL实例</a></p>
<h2 id="Druid"><a href="#Druid" class="headerlink" title="Druid"></a>Druid</h2><p>本来准备计划试试，但自己SpringBoot学艺不精，再加上最后选用了Django，项目后期就没有在考虑了</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_22165667/article/details/116738993">springboot集成hive，使用druid连接池</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_39035773/article/details/107854357">druid-spring-boot-starter整合hive遇到的一个小坑</a></p>
<h2 id="Sqoop"><a href="#Sqoop" class="headerlink" title="Sqoop"></a>Sqoop</h2><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://zhuanlan.zhihu.com/p/444568213">大数据开发之Sqoop详细介绍</a></p>
<p>Sqoop 2021年停止维护</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://zhuanlan.zhihu.com/p/106785329">sqoop快速上手简明教程</a></p>
<p>我看组员最后数据分析用了SPSSPRO</p>
<h2 id="PyHive"><a href="#PyHive" class="headerlink" title="PyHive"></a>PyHive</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">pip install sasl</span><br><span class="line">pip install thrift</span><br><span class="line">pip install thrift-sasl</span><br><span class="line">pip install PyHive</span><br></pre></td></tr></table></figure>

<p>但Windows下安装报错</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">C:\Users\Administrator\AppData\Local\Temp\pip-install-7_4i0p52\sasl_bd6a6fbee8074cf6814556fa3e26c960\sasl\saslwrapper.h(22): fatal error C1083: 无法打开包括文件: “sasl/sasl.h”: No such file or directory</span><br></pre></td></tr></table></figure>

<p>最后证明PyHive依赖于Linux的组件，在Ubuntu上运行起来了</p>
<h2 id="insert-overwrite操作"><a href="#insert-overwrite操作" class="headerlink" title="insert overwrite操作"></a>insert overwrite操作</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> emp;</span><br><span class="line"><span class="keyword">insert</span> overwrite <span class="keyword">table</span> emp <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> emp <span class="keyword">where</span> emp_name <span class="keyword">is</span> <span class="keyword">not</span> <span class="keyword">null</span>;</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> dept;</span><br></pre></td></tr></table></figure>

<p>在Hive中，DELETE操作的替代方式是使用INSERT INTO语句将要保留的数据插入到新的表中，然后重命名新表覆盖原始表。这种方式被称为“Insert-Overwrite”。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> overwrite <span class="keyword">table</span> <span class="keyword">order</span></span><br></pre></td></tr></table></figure>



<h1 id="Centos踩坑"><a href="#Centos踩坑" class="headerlink" title="Centos踩坑"></a>Centos踩坑</h1><h2 id="ssh登录过慢"><a href="#ssh登录过慢" class="headerlink" title="ssh登录过慢"></a>ssh登录过慢</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">1.su                           (以root用户登录)</span><br><span class="line">2.vim /etc/ssh/sshd_config      (编辑配置文件)</span><br><span class="line">3.输入 /, 查找GSSAPIAuthentication  赋值为 no(默认为yes)</span><br><span class="line">4.输入 /, 查找UseDNS,赋值为 no(该项默认不启用的，要把前面的#删除掉)</span><br><span class="line">————————————————</span><br><span class="line">版权声明：本文为CSDN博主「skyxiaolv」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。</span><br><span class="line">原文链接：https://blog.csdn.net/lixialv/article/details/107670539</span><br></pre></td></tr></table></figure>

<h1 id="Themlef"><a href="#Themlef" class="headerlink" title="Themlef"></a>Themlef</h1><p>最后项目结束答辩的其中一个成果，是做页面进行数据展示。整个小组里只有我能完成前端与后端的工作，为了省时间就只能选前后端一体的方案。SpringBoot+Themlef是我当时比较中意的一个方案</p>
<p>需要starter-web</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="Layui"><a href="#Layui" class="headerlink" title="Layui"></a>Layui</h2><p>如果前后端是一体的话推荐使用这个</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="http://layui.org.cn/docs/docs.html#install">Layui </a></p>
<h2 id="启动配置"><a href="#启动配置" class="headerlink" title="启动配置"></a>启动配置</h2><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/weixin_42293359/article/details/106078829">SpringBoot整合Thymeleaf快速入门（附详细教程）</a></p>
<h2 id="准表达式语法"><a href="#准表达式语法" class="headerlink" title="准表达式语法"></a>准表达式语法</h2><p>Thymeleaf 模板引擎支持多种表达式：</p>
<ul>
<li>变量表达式：${…}</li>
<li>选择变量表达式：*{…}</li>
<li>链接表达式：@{…}</li>
<li>国际化表达式：#{…}</li>
<li>片段引用表达式：~{…}</li>
</ul>
<p>① 获取对象的属性和方法</p>
<p>使用变量表达式可以获取对象的属性和方法，例如，获取 person 对象的 lastName 属性，表达式形式如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$&#123;person.lastName&#125;</span><br></pre></td></tr></table></figure>

<p>② 使用内置的基本对象</p>
<p>使用变量表达式还可以使用内置基本对象，获取内置对象的属性，调用内置对象的方法。 Thymeleaf 中常用的内置基本对象如下：</p>
<ul>
<li>#ctx ：上下文对象；</li>
<li>#vars ：上下文变量；</li>
<li>#locale：上下文的语言环境；</li>
<li>#request：HttpServletRequest 对象（仅在 Web 应用中可用）；</li>
<li>#response：HttpServletResponse 对象（仅在 Web 应用中可用）；</li>
<li>#session：HttpSession 对象（仅在 Web 应用中可用）；</li>
<li>#servletContext：ServletContext 对象（仅在 Web 应用中可用）。</li>
</ul>
<p>例如，我们通过以下 2 种形式，都可以获取到 session 对象中的 map 属性：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$&#123;#session.getAttribute(&#x27;map&#x27;)&#125;$&#123;session.map&#125;</span><br></pre></td></tr></table></figure>

<p>③ 使用内置的工具对象</p>
<p>除了能使用内置的基本对象外，变量表达式还可以使用一些内置的工具对象。</p>
<ul>
<li>strings：字符串工具对象，常用方法有：equals、equalsIgnoreCase、length、trim、toUpperCase、toLowerCase、indexOf、substring、replace、startsWith、endsWith，contains 和 containsIgnoreCase 等；</li>
<li>numbers：数字工具对象，常用的方法有：formatDecimal 等；</li>
<li>bools：布尔工具对象，常用的方法有：isTrue 和 isFalse 等；</li>
<li>arrays：数组工具对象，常用的方法有：toArray、length、isEmpty、contains 和 containsAll 等；</li>
<li>lists&#x2F;sets：List&#x2F;Set 集合工具对象，常用的方法有：toList、size、isEmpty、contains、containsAll 和 sort 等；</li>
<li>maps：Map 集合工具对象，常用的方法有：size、isEmpty、containsKey 和 containsValue 等；</li>
<li>dates：日期工具对象，常用的方法有：format、year、month、hour 和 createNow 等。</li>
</ul>
<p>例如，我们可以使用内置工具对象 strings 的 equals 方法，来判断字符串与对象的某个属性是否相等，代码如下。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">纯文本复制</span><br><span class="line">$&#123;#strings.equals(&#x27;编程帮&#x27;,name)&#125;</span><br></pre></td></tr></table></figure>



<h2 id="与js结合"><a href="#与js结合" class="headerlink" title="与js结合"></a>与js结合</h2><p>必须单独创建一个变量</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">th:inline</span>=<span class="string">&quot;javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="keyword">var</span> fs1 = [[$&#123;fs1&#125;]];</span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">console</span>.<span class="title function_">log</span>(fs1);</span></span><br><span class="line"><span class="language-javascript">    <span class="keyword">var</span> user = <span class="comment">/*[[$&#123;user&#125;]]*/</span> <span class="literal">null</span>;</span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">console</span>.<span class="title function_">log</span>(user)</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>或者用each</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tr</span> <span class="attr">th:each</span>=<span class="string">&quot;book : $&#123;books&#125;&quot;</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;book.author&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;book.title&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;book.url&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">script</span> <span class="attr">th:inline</span>=<span class="string">&quot;javascript&quot;</span>&gt;</span><span class="language-javascript"><span class="comment">//一定要加上这句</span></span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">function</span> <span class="title function_">localRefresh</span>(<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="comment">// 装载局部刷新返回的页面</span></span></span><br><span class="line"><span class="language-javascript">            $(<span class="string">&#x27;#table_refresh2&#x27;</span>).<span class="title function_">load</span>(<span class="string">&quot;/local/&quot;</span>+[[$&#123;book.<span class="property">ID</span>&#125;]]);<span class="comment">//这里直接可以使用thymeleaf中的变量，通过内联样式</span></span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tr</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="th语法"><a href="#th语法" class="headerlink" title="th语法"></a>th语法</h2><table>
<thead>
<tr>
<th>属性</th>
<th>描述</th>
<th>示例</th>
</tr>
</thead>
<tbody><tr>
<td>th:id</td>
<td>替换 HTML 的 id 属性</td>
<td><code>&lt;input  id=&quot;html-id&quot;  th:id=&quot;thymeleaf-id&quot;  /&gt;</code></td>
</tr>
<tr>
<td>th:text</td>
<td>文本替换，转义特殊字符</td>
<td><code>&lt;h1 th:text=&quot;hello，bianchengbang&quot; &gt;hello&lt;/h1&gt;</code></td>
</tr>
<tr>
<td>th:utext</td>
<td>文本替换，不转义特殊字符</td>
<td><code>&lt;div th:utext=&quot;&#39;&lt;h1&gt;欢迎来到编程帮！&lt;/h1&gt;&#39;&quot; &gt;欢迎你&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:object</td>
<td>在父标签选择对象，子标签使用 *{…} 选择表达式选取值。 没有选择对象，那子标签使用选择表达式和 ${…} 变量表达式是一样的效果。 同时即使选择了对象，子标签仍然可以使用变量表达式。</td>
<td><code>&lt;div th:object=&quot;$&#123;session.user&#125;&quot; &gt;    &lt;p th:text=&quot;*&#123;fisrtName&#125;&quot;&gt;firstname&lt;/p&gt;&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:value</td>
<td>替换 value 属性</td>
<td><code>&lt;input th:value = &quot;$&#123;user.name&#125;&quot; /&gt;</code></td>
</tr>
<tr>
<td>th:with</td>
<td>局部变量赋值运算</td>
<td><code>&lt;div th:with=&quot;isEvens = $&#123;prodStat.count&#125;%2 == 0&quot;  th:text=&quot;$&#123;isEvens&#125;&quot;&gt;&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:style</td>
<td>设置样式</td>
<td><code>&lt;div th:style=&quot;&#39;color:#F00; font-weight:bold&#39;&quot;&gt;编程帮 www.biancheng.net&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:onclick</td>
<td>点击事件</td>
<td><code>&lt;td th:onclick = &quot;&#39;getInfo()&#39;&quot;&gt;&lt;/td&gt;</code></td>
</tr>
<tr>
<td>th:each</td>
<td>遍历，支持 Iterable、Map、数组等。</td>
<td><code>&lt;table&gt;    &lt;tr th:each=&quot;m:$&#123;session.map&#125;&quot;&gt;        &lt;td th:text=&quot;$&#123;m.getKey()&#125;&quot;&gt;&lt;/td&gt;        &lt;td th:text=&quot;$&#123;m.getValue()&#125;&quot;&gt;&lt;/td&gt;    &lt;/tr&gt;&lt;/table&gt;</code></td>
</tr>
<tr>
<td>th:if</td>
<td>根据条件判断是否需要展示此标签</td>
<td><code>&lt;a th:if =&quot;$&#123;userId == collect.userId&#125;&quot;&gt;</code></td>
</tr>
<tr>
<td>th:unless</td>
<td>和 th:if 判断相反，满足条件时不显示</td>
<td><code> &lt;div th:unless=&quot;$&#123;m.getKey()==&#39;name&#39;&#125;&quot; &gt;&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:switch</td>
<td>与 Java 的 switch case语句类似 通常与 th:case 配合使用，根据不同的条件展示不同的内容</td>
<td><code>&lt;div th:switch=&quot;$&#123;name&#125;&quot;&gt;    &lt;span th:case=&quot;a&quot;&gt;编程帮&lt;/span&gt;    &lt;span th:case=&quot;b&quot;&gt;www.biancheng.net&lt;/span&gt;&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:fragment</td>
<td>模板布局，类似 JSP 的 tag，用来定义一段被引用或包含的模板片段</td>
<td><code>&lt;footer th:fragment=&quot;footer&quot;&gt;插入的内容&lt;/footer&gt;</code></td>
</tr>
<tr>
<td>th:insert</td>
<td>布局标签； 将使用 th:fragment 属性指定的模板片段（包含标签）插入到当前标签中。</td>
<td><code>&lt;div th:insert=&quot;commons/bar::footer&quot;&gt;&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:replace</td>
<td>布局标签； 使用 th:fragment 属性指定的模板片段（包含标签）替换当前整个标签。</td>
<td><code>&lt;div th:replace=&quot;commons/bar::footer&quot;&gt;&lt;/div&gt;</code></td>
</tr>
<tr>
<td>th:selected</td>
<td>select 选择框选中</td>
<td><code>&lt;select&gt;    &lt;option&gt;---&lt;/option&gt;    &lt;option th:selected=&quot;$&#123;name==&#39;a&#39;&#125;&quot;&gt;        编程帮    &lt;/option&gt;    &lt;option th:selected=&quot;$&#123;name==&#39;b&#39;&#125;&quot;&gt;        www.biancheng.net    &lt;/option&gt;&lt;/select&gt;</code></td>
</tr>
<tr>
<td>th:src</td>
<td>替换 HTML 中的 src 属性</td>
<td><code>&lt;img  th:src=&quot;@&#123;/asserts/img/bootstrap-solid.svg&#125;&quot; src=&quot;asserts/img/bootstrap-solid.svg&quot; /&gt;</code></td>
</tr>
<tr>
<td>th:inline</td>
<td>内联属性； 该属性有 text、none、javascript 三种取值， 在 <script> 标签中使用时，js 代码中可以获取到后台传递页面的对象。</td>
<td><code>&lt;script type=&quot;text/javascript&quot; th:inline=&quot;javascript&quot;&gt;    var name = /*[[$&#123;name&#125;]]*/ &#39;bianchengbang&#39;;    alert(name)&lt;/script&gt;</code></td>
</tr>
<tr>
<td>th:action</td>
<td>替换表单提交地址</td>
<td><code>&lt;form th:action=&quot;@&#123;/user/login&#125;&quot; th:method=&quot;post&quot;&gt;&lt;/form&gt;</code></td>
</tr>
</tbody></table>
<h2 id="Example-1"><a href="#Example-1" class="headerlink" title="Example"></a>Example</h2><h3 id="index-html"><a href="#index-html" class="headerlink" title="index.html"></a>index.html</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">xmlns:th</span>=<span class="string">&quot;http://www.thymeleaf.org&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>Thymeleaf的入门<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;Content-Type&quot;</span> <span class="attr">content</span>=<span class="string">&quot;text/html; charset=UTF-8&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;hello&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="index-java"><a href="#index-java" class="headerlink" title="index.java"></a>index.java</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Controller;</span><br><span class="line"><span class="keyword">import</span> org.springframework.ui.Model;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> MocusEZ</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2023/6/23 14:42</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Controller</span></span><br><span class="line"><span class="meta">@RequestMapping(&quot;/test&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestController</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/***</span></span><br><span class="line"><span class="comment">     * 访问/test/hello  跳转到templates_1页面</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> model</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@RequestMapping(&quot;/hello&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">hello</span><span class="params">(Model model)</span>&#123;</span><br><span class="line">        model.addAttribute(<span class="string">&quot;hello&quot;</span>,<span class="string">&quot;What a wonderful world!&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;index&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h1 id="ECharts测试"><a href="#ECharts测试" class="headerlink" title="ECharts测试"></a>ECharts测试</h1><p>数据展示选用了ECharts组件，效果看起来不错。</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://echarts.apache.org/handbook/zh/get-started/">Echarts</a></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;utf-8&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>ECharts<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 引入刚刚下载的 ECharts 文件 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;echarts.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 为 ECharts 准备一个定义了宽高的 DOM --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;main&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width: 600px;height:400px;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 基于准备好的dom，初始化echarts实例</span></span></span><br><span class="line"><span class="language-javascript">      <span class="keyword">var</span> myChart = echarts.<span class="title function_">init</span>(<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;main&#x27;</span>));</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 指定图表的配置项和数据</span></span></span><br><span class="line"><span class="language-javascript">      <span class="keyword">var</span> option = &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">title</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">          <span class="attr">text</span>: <span class="string">&#x27;Hello Wolrd&#x27;</span></span></span><br><span class="line"><span class="language-javascript">        &#125;,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">tooltip</span>: &#123;&#125;,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">legend</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">          <span class="attr">data</span>: [<span class="string">&#x27;销量&#x27;</span>]</span></span><br><span class="line"><span class="language-javascript">        &#125;,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">xAxis</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">          <span class="attr">data</span>: [<span class="string">&#x27;衬衫&#x27;</span>, <span class="string">&#x27;羊毛衫&#x27;</span>, <span class="string">&#x27;雪纺衫&#x27;</span>, <span class="string">&#x27;裤子&#x27;</span>, <span class="string">&#x27;高跟鞋&#x27;</span>, <span class="string">&#x27;袜子&#x27;</span>]</span></span><br><span class="line"><span class="language-javascript">        &#125;,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">yAxis</span>: &#123;&#125;,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">series</span>: [</span></span><br><span class="line"><span class="language-javascript">          &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">name</span>: <span class="string">&#x27;销量&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">data</span>: [<span class="number">5</span>, <span class="number">20</span>, <span class="number">36</span>, <span class="number">10</span>, <span class="number">10</span>, <span class="number">20</span>]</span></span><br><span class="line"><span class="language-javascript">          &#125;</span></span><br><span class="line"><span class="language-javascript">        ]</span></span><br><span class="line"><span class="language-javascript">      &#125;;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 使用刚指定的配置项和数据显示图表。</span></span></span><br><span class="line"><span class="language-javascript">      myChart.<span class="title function_">setOption</span>(option);</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="图表容器及其大小"><a href="#图表容器及其大小" class="headerlink" title="图表容器及其大小"></a>图表容器及其大小</h2><h3 id="初始化"><a href="#初始化" class="headerlink" title="初始化"></a>初始化</h3><h4 id="在-HTML-中定义有宽度和高度的父容器（推荐）"><a href="#在-HTML-中定义有宽度和高度的父容器（推荐）" class="headerlink" title="在 HTML 中定义有宽度和高度的父容器（推荐）"></a>在 HTML 中定义有宽度和高度的父容器（推荐）</h4><p>通常来说，需要在 HTML 中先定义一个 <code>&lt;div&gt;</code> 节点，并且通过 CSS 使得该节点具有宽度和高度。初始化的时候，传入该节点，图表的大小默认即为该节点的大小，除非声明了 <code>opts.width</code> 或 <code>opts.height</code> 将其覆盖。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;main&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width: 600px;height:400px;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">  <span class="keyword">var</span> myChart = echarts.<span class="title function_">init</span>(<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;main&#x27;</span>));</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>



<p>需要注意的是，使用这种方法在调用 <code>echarts.init</code> 时需保证容器已经有宽度和高度了。</p>
<h4 id="指定图表的大小"><a href="#指定图表的大小" class="headerlink" title="指定图表的大小"></a>指定图表的大小</h4><p>如果图表容器不存在宽度和高度，或者，你希望图表宽度和高度不等于容器大小，也可以在初始化的时候指定大小。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;main&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">  <span class="keyword">var</span> myChart = echarts.<span class="title function_">init</span>(<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;main&#x27;</span>), <span class="literal">null</span>, &#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">width</span>: <span class="number">600</span>,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">height</span>: <span class="number">400</span></span></span><br><span class="line"><span class="language-javascript">  &#125;);</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h3 id="响应容器大小的变化"><a href="#响应容器大小的变化" class="headerlink" title="响应容器大小的变化"></a>响应容器大小的变化</h3><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://echarts.apache.org/handbook/zh/concepts/chart-size">https://echarts.apache.org/handbook/zh/concepts/chart-size</a></p>
<h2 id="样式"><a href="#样式" class="headerlink" title="样式"></a>样式</h2><p>ECharts5 除了一贯的默认主题外，还内置了<code>&#39;dark&#39;</code>主题。可以像这样切换成深色模式：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> chart = echarts.<span class="title function_">init</span>(dom, <span class="string">&#x27;dark&#x27;</span>);</span><br></pre></td></tr></table></figure>



<h2 id="数据集"><a href="#数据集" class="headerlink" title="数据集"></a>数据集</h2><p><code>数据集（dataset）</code>是专门用来管理数据的组件。虽然每个系列都可以在 <code>series.data</code> 中设置数据，但是从 ECharts4 支持数据集开始，更推荐使用数据集来管理数据。因为这样，数据可以被多个组件复用，也方便进行 “数据和其他配置” 分离的配置风格。毕竟，在运行时，数据是最常改变的，而其他配置大多并不会改变。</p>
<h3 id="在系列中设置数据"><a href="#在系列中设置数据" class="headerlink" title="在系列中设置数据"></a>在系列中设置数据</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span>,</span><br><span class="line">    <span class="attr">data</span>: [<span class="string">&#x27;Matcha Latte&#x27;</span>, <span class="string">&#x27;Milk Tea&#x27;</span>, <span class="string">&#x27;Cheese Cocoa&#x27;</span>, <span class="string">&#x27;Walnut Brownie&#x27;</span>]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;2015&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">89.3</span>, <span class="number">92.1</span>, <span class="number">94.4</span>, <span class="number">85.4</span>]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;2016&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">95.8</span>, <span class="number">89.4</span>, <span class="number">91.2</span>, <span class="number">76.9</span>]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;2017&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">97.7</span>, <span class="number">83.1</span>, <span class="number">92.5</span>, <span class="number">78.1</span>]</span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>这种方式的优点是，适于对一些特殊的数据结构（如“树”、“图”、超大数据）进行一定的数据类型定制。 但是缺点是，常需要用户先处理数据，把数据分割设置到各个系列（和类目轴）中。此外，不利于多个系列共享一份数据，也不利于基于原始数据进行图表类型、系列的映射安排。</p>
<h3 id="在数据集中设置数据"><a href="#在数据集中设置数据" class="headerlink" title="在数据集中设置数据"></a>在数据集中设置数据</h3><p>而数据设置在 <code>数据集（dataset）</code> 中，会有这些好处：</p>
<ul>
<li>能够贴近数据可视化常见思维方式：（I）提供数据，（II）指定数据到视觉的映射，从而形成图表。</li>
<li>数据和其他配置可以被分离开来。数据常变，其他配置常不变。分开易于分别管理。</li>
<li>数据可以被多个系列或者组件复用，对于大数据量的场景，不必为每个系列创建一份数据。</li>
<li>支持更多的数据的常用格式，例如二维数组、对象数组等，一定程度上避免使用者为了数据格式而进行转换。</li>
</ul>
<p>下面是一个最简单的 <code>dataset</code> 的例子：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">legend</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">tooltip</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">dataset</span>: &#123;</span><br><span class="line">    <span class="comment">// 提供一份数据。</span></span><br><span class="line">    <span class="attr">source</span>: [</span><br><span class="line">      [<span class="string">&#x27;product&#x27;</span>, <span class="string">&#x27;2015&#x27;</span>, <span class="string">&#x27;2016&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>],</span><br><span class="line">      [<span class="string">&#x27;Matcha Latte&#x27;</span>, <span class="number">43.3</span>, <span class="number">85.8</span>, <span class="number">93.7</span>],</span><br><span class="line">      [<span class="string">&#x27;Milk Tea&#x27;</span>, <span class="number">83.1</span>, <span class="number">73.4</span>, <span class="number">55.1</span>],</span><br><span class="line">      [<span class="string">&#x27;Cheese Cocoa&#x27;</span>, <span class="number">86.4</span>, <span class="number">65.2</span>, <span class="number">82.5</span>],</span><br><span class="line">      [<span class="string">&#x27;Walnut Brownie&#x27;</span>, <span class="number">72.4</span>, <span class="number">53.9</span>, <span class="number">39.1</span>]</span><br><span class="line">    ]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// 声明一个 X 轴，类目轴（category）。默认情况下，类目轴对应到 dataset 第一列。</span></span><br><span class="line">  <span class="attr">xAxis</span>: &#123; <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span> &#125;,</span><br><span class="line">  <span class="comment">// 声明一个 Y 轴，数值轴。</span></span><br><span class="line">  <span class="attr">yAxis</span>: &#123;&#125;,</span><br><span class="line">  <span class="comment">// 声明多个 bar 系列，默认情况下，每个系列会自动对应到 dataset 的每一列。</span></span><br><span class="line">  <span class="attr">series</span>: [&#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span> &#125;, &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span> &#125;, &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span> &#125;]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h3 id="数据到图形的映射"><a href="#数据到图形的映射" class="headerlink" title="数据到图形的映射"></a>数据到图形的映射</h3><p>如上所述，数据可视化的一个常见思路是：（I）提供数据，（II）指定数据到视觉的映射。</p>
<p>简而言之，可以进行这些映射的设定：</p>
<ul>
<li>指定 <code>数据集</code> 的列（column）还是行（row）映射为 <code>系列（series）</code>。这件事可以使用 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://echarts.apache.org/option.html#series.seriesLayoutBy">series.seriesLayoutBy</a> 属性来配置。默认是按照列（column）来映射。</li>
<li>指定维度映射的规则：如何从 dataset 的维度（一个“维度”的意思是一行/列）映射到坐标轴（如 X、Y 轴）、提示框（tooltip）、标签（label）、图形元素大小颜色等（visualMap）。这件事可以使用 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://echarts.apache.org/option.html#series.encode">series.encode</a> 属性，以及 <a target="_blank" rel="noopener external nofollow noreferrer" href="https://echarts.apache.org/option.html#visualMap">visualMap</a> 组件来配置（如果有需要映射颜色大小等视觉维度的话）。上面的例子中，没有给出这种映射配置，那么 ECharts 就按最常见的理解进行默认映射：X 坐标轴声明为类目轴，默认情况下会自动对应到 <code>dataset.source</code> 中的第一列；三个柱图系列，一一对应到 <code>dataset.source</code> 中后面每一列。</li>
</ul>
<p>下面详细解释这些映射的设定。</p>
<h3 id="把数据集（dataset）的行或列映射为系列（series）"><a href="#把数据集（dataset）的行或列映射为系列（series）" class="headerlink" title="把数据集（dataset）的行或列映射为系列（series）"></a>把数据集（dataset）的行或列映射为系列（series）</h3><p>有了数据表之后，使用者可以灵活地配置：数据如何对应到轴和图形系列。</p>
<p>用户可以使用 <code>seriesLayoutBy</code> 配置项，改变图表对于行列的理解。<code>seriesLayoutBy</code> 可取值：</p>
<ul>
<li><code>&#39;column&#39;</code>: 默认值。系列被安放到 <code>dataset</code> 的列上面。</li>
<li><code>&#39;row&#39;</code>: 系列被安放到 <code>dataset</code> 的行上面。</li>
</ul>
<p>看这个例子：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">legend</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">tooltip</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">dataset</span>: &#123;</span><br><span class="line">    <span class="attr">source</span>: [</span><br><span class="line">      [<span class="string">&#x27;product&#x27;</span>, <span class="string">&#x27;2012&#x27;</span>, <span class="string">&#x27;2013&#x27;</span>, <span class="string">&#x27;2014&#x27;</span>, <span class="string">&#x27;2015&#x27;</span>],</span><br><span class="line">      [<span class="string">&#x27;Matcha Latte&#x27;</span>, <span class="number">41.1</span>, <span class="number">30.4</span>, <span class="number">65.1</span>, <span class="number">53.3</span>],</span><br><span class="line">      [<span class="string">&#x27;Milk Tea&#x27;</span>, <span class="number">86.5</span>, <span class="number">92.1</span>, <span class="number">85.7</span>, <span class="number">83.1</span>],</span><br><span class="line">      [<span class="string">&#x27;Cheese Cocoa&#x27;</span>, <span class="number">24.1</span>, <span class="number">67.2</span>, <span class="number">79.5</span>, <span class="number">86.4</span>]</span><br><span class="line">    ]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">xAxis</span>: [</span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span>, <span class="attr">gridIndex</span>: <span class="number">0</span> &#125;,</span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span>, <span class="attr">gridIndex</span>: <span class="number">1</span> &#125;</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">yAxis</span>: [&#123; <span class="attr">gridIndex</span>: <span class="number">0</span> &#125;, &#123; <span class="attr">gridIndex</span>: <span class="number">1</span> &#125;],</span><br><span class="line">  <span class="attr">grid</span>: [&#123; <span class="attr">bottom</span>: <span class="string">&#x27;55%&#x27;</span> &#125;, &#123; <span class="attr">top</span>: <span class="string">&#x27;55%&#x27;</span> &#125;],</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    <span class="comment">// 这几个系列会出现在第一个直角坐标系中，每个系列对应到 dataset 的每一行。</span></span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>, <span class="attr">seriesLayoutBy</span>: <span class="string">&#x27;row&#x27;</span> &#125;,</span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>, <span class="attr">seriesLayoutBy</span>: <span class="string">&#x27;row&#x27;</span> &#125;,</span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>, <span class="attr">seriesLayoutBy</span>: <span class="string">&#x27;row&#x27;</span> &#125;,</span><br><span class="line">    <span class="comment">// 这几个系列会出现在第二个直角坐标系中，每个系列对应到 dataset 的每一列。</span></span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>, <span class="attr">xAxisIndex</span>: <span class="number">1</span>, <span class="attr">yAxisIndex</span>: <span class="number">1</span> &#125;,</span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>, <span class="attr">xAxisIndex</span>: <span class="number">1</span>, <span class="attr">yAxisIndex</span>: <span class="number">1</span> &#125;,</span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>, <span class="attr">xAxisIndex</span>: <span class="number">1</span>, <span class="attr">yAxisIndex</span>: <span class="number">1</span> &#125;,</span><br><span class="line">    &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>, <span class="attr">xAxisIndex</span>: <span class="number">1</span>, <span class="attr">yAxisIndex</span>: <span class="number">1</span> &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>



<h2 id="坐标轴"><a href="#坐标轴" class="headerlink" title="坐标轴"></a>坐标轴</h2><h3 id="x-轴、y-轴"><a href="#x-轴、y-轴" class="headerlink" title="x 轴、y 轴"></a>x 轴、y 轴</h3><p>x 轴和 y 轴都由轴线、刻度、刻度标签、轴标题四个部分组成。部分图表中还会有网格线来帮助查看和计算数据</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&#x27;time&#x27;</span>,</span><br><span class="line">    <span class="attr">name</span>: <span class="string">&#x27;销售时间&#x27;</span></span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&#x27;value&#x27;</span>,</span><br><span class="line">    <span class="attr">name</span>: <span class="string">&#x27;销售数量&#x27;</span></span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h3 id="Example-2"><a href="#Example-2" class="headerlink" title="Example"></a>Example</h3><p>图左侧的 y 轴代表东京月平均气温，右侧的 y 轴表示东京降水量，x 轴表示时间。两组 y 轴在一起，反映了平均气温和降水量间的趋势关系。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">tooltip</span>: &#123;</span><br><span class="line">    <span class="attr">trigger</span>: <span class="string">&#x27;axis&#x27;</span>,</span><br><span class="line">    <span class="attr">axisPointer</span>: &#123; <span class="attr">type</span>: <span class="string">&#x27;cross&#x27;</span> &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">legend</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">xAxis</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span>,</span><br><span class="line">      <span class="attr">axisTick</span>: &#123;</span><br><span class="line">        <span class="attr">alignWithLabel</span>: <span class="literal">true</span></span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">data</span>: [</span><br><span class="line">        <span class="string">&#x27;1月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;2月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;3月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;4月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;5月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;6月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;7月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;8月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;9月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;10月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;11月&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;12月&#x27;</span></span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">yAxis</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;value&#x27;</span>,</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;降水量&#x27;</span>,</span><br><span class="line">      <span class="attr">min</span>: <span class="number">0</span>,</span><br><span class="line">      <span class="attr">max</span>: <span class="number">250</span>,</span><br><span class="line">      <span class="attr">position</span>: <span class="string">&#x27;right&#x27;</span>,</span><br><span class="line">      <span class="attr">axisLabel</span>: &#123;</span><br><span class="line">        <span class="attr">formatter</span>: <span class="string">&#x27;&#123;value&#125; ml&#x27;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;value&#x27;</span>,</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;温度&#x27;</span>,</span><br><span class="line">      <span class="attr">min</span>: <span class="number">0</span>,</span><br><span class="line">      <span class="attr">max</span>: <span class="number">25</span>,</span><br><span class="line">      <span class="attr">position</span>: <span class="string">&#x27;left&#x27;</span>,</span><br><span class="line">      <span class="attr">axisLabel</span>: &#123;</span><br><span class="line">        <span class="attr">formatter</span>: <span class="string">&#x27;&#123;value&#125; °C&#x27;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;降水量&#x27;</span>,</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">yAxisIndex</span>: <span class="number">0</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">6</span>, <span class="number">32</span>, <span class="number">70</span>, <span class="number">86</span>, <span class="number">68.7</span>, <span class="number">100.7</span>, <span class="number">125.6</span>, <span class="number">112.2</span>, <span class="number">78.7</span>, <span class="number">48.8</span>, <span class="number">36.0</span>, <span class="number">19.3</span>]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;温度&#x27;</span>,</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;line&#x27;</span>,</span><br><span class="line">      <span class="attr">smooth</span>: <span class="literal">true</span>,</span><br><span class="line">      <span class="attr">yAxisIndex</span>: <span class="number">1</span>,</span><br><span class="line">      <span class="attr">data</span>: [</span><br><span class="line">        <span class="number">6.0</span>,</span><br><span class="line">        <span class="number">10.2</span>,</span><br><span class="line">        <span class="number">10.3</span>,</span><br><span class="line">        <span class="number">11.5</span>,</span><br><span class="line">        <span class="number">10.3</span>,</span><br><span class="line">        <span class="number">13.2</span>,</span><br><span class="line">        <span class="number">14.3</span>,</span><br><span class="line">        <span class="number">16.4</span>,</span><br><span class="line">        <span class="number">18.0</span>,</span><br><span class="line">        <span class="number">16.5</span>,</span><br><span class="line">        <span class="number">12.0</span>,</span><br><span class="line">        <span class="number">5.2</span></span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>



<h2 id="图例"><a href="#图例" class="headerlink" title="图例"></a>图例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">legend</span>: &#123;</span><br><span class="line">    <span class="comment">// Try &#x27;horizontal&#x27;</span></span><br><span class="line">    <span class="attr">orient</span>: <span class="string">&#x27;vertical&#x27;</span>,</span><br><span class="line">    <span class="attr">right</span>: <span class="number">10</span>,</span><br><span class="line">    <span class="attr">top</span>: <span class="string">&#x27;center&#x27;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">dataset</span>: &#123;</span><br><span class="line">    <span class="attr">source</span>: [</span><br><span class="line">      [<span class="string">&#x27;product&#x27;</span>, <span class="string">&#x27;2015&#x27;</span>, <span class="string">&#x27;2016&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>],</span><br><span class="line">      [<span class="string">&#x27;Matcha Latte&#x27;</span>, <span class="number">43.3</span>, <span class="number">85.8</span>, <span class="number">93.7</span>],</span><br><span class="line">      [<span class="string">&#x27;Milk Tea&#x27;</span>, <span class="number">83.1</span>, <span class="number">73.4</span>, <span class="number">55.1</span>],</span><br><span class="line">      [<span class="string">&#x27;Cheese Cocoa&#x27;</span>, <span class="number">86.4</span>, <span class="number">65.2</span>, <span class="number">82.5</span>],</span><br><span class="line">      [<span class="string">&#x27;Walnut Brownie&#x27;</span>, <span class="number">72.4</span>, <span class="number">53.9</span>, <span class="number">39.1</span>]</span><br><span class="line">    ]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">xAxis</span>: &#123; <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span> &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">series</span>: [&#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span> &#125;, &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span> &#125;, &#123; <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span> &#125;]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>



<h2 id="事件与行为"><a href="#事件与行为" class="headerlink" title="事件与行为"></a>事件与行为</h2><p>在 Apache ECharts 的图表中用户的操作将会触发相应的事件。开发者可以监听这些事件，然后通过回调函数做相应的处理，比如跳转到一个地址，或者弹出对话框，或者做数据下钻等等。</p>
<p>ECharts 中的事件名称对应 DOM 事件名称，均为小写的字符串，如下是一个绑定点击操作的示例。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">myChart.<span class="title function_">on</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span>(<span class="params">params</span>) &#123;</span><br><span class="line">  <span class="comment">// 控制台打印数据的名称</span></span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(params.<span class="property">name</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h3 id="鼠标事件处理"><a href="#鼠标事件处理" class="headerlink" title="鼠标事件处理"></a>鼠标事件处理</h3><p>ECharts 支持常规的鼠标事件类型，包括 <code>&#39;click&#39;</code>、 <code>&#39;dblclick&#39;</code>、 <code>&#39;mousedown&#39;</code>、 <code>&#39;mousemove&#39;</code>、 <code>&#39;mouseup&#39;</code>、 <code>&#39;mouseover&#39;</code>、 <code>&#39;mouseout&#39;</code>、 <code>&#39;globalout&#39;</code>、 <code>&#39;contextmenu&#39;</code> 事件。下面先来看一个简单的点击柱状图后打开相应的百度搜索页面的示例。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 基于准备好的dom，初始化ECharts实例</span></span><br><span class="line"><span class="comment">// var myChart = echarts.init(document.getElementById(&#x27;main&#x27;));</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 指定图表的配置项和数据</span></span><br><span class="line"><span class="keyword">var</span> option = &#123;</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">data</span>: [<span class="string">&#x27;衬衫&#x27;</span>, <span class="string">&#x27;羊毛衫&#x27;</span>, <span class="string">&#x27;雪纺衫&#x27;</span>, <span class="string">&#x27;裤子&#x27;</span>, <span class="string">&#x27;高跟鞋&#x27;</span>, <span class="string">&#x27;袜子&#x27;</span>]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;销量&#x27;</span>,</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">5</span>, <span class="number">20</span>, <span class="number">36</span>, <span class="number">10</span>, <span class="number">10</span>, <span class="number">20</span>]</span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">// 使用刚指定的配置项和数据显示图表。</span></span><br><span class="line">myChart.<span class="title function_">setOption</span>(option);</span><br><span class="line"><span class="comment">// 处理点击事件并且跳转到相应的百度搜索页面</span></span><br><span class="line">myChart.<span class="title function_">on</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span>(<span class="params">params</span>) &#123;</span><br><span class="line">  <span class="variable language_">window</span>.<span class="title function_">open</span>(<span class="string">&#x27;https://www.baidu.com/s?wd=&#x27;</span> + <span class="built_in">encodeURIComponent</span>(params.<span class="property">name</span>));</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>



<h2 id="常用图标"><a href="#常用图标" class="headerlink" title="常用图标"></a>常用图标</h2><h3 id="柱状图"><a href="#柱状图" class="headerlink" title="柱状图"></a>柱状图</h3><h4 id="简单柱状图"><a href="#简单柱状图" class="headerlink" title="简单柱状图"></a>简单柱状图</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">data</span>: [<span class="string">&#x27;Mon&#x27;</span>, <span class="string">&#x27;Tue&#x27;</span>, <span class="string">&#x27;Wed&#x27;</span>, <span class="string">&#x27;Thu&#x27;</span>, <span class="string">&#x27;Fri&#x27;</span>, <span class="string">&#x27;Sat&#x27;</span>, <span class="string">&#x27;Sun&#x27;</span>]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">23</span>, <span class="number">24</span>, <span class="number">18</span>, <span class="number">25</span>, <span class="number">27</span>, <span class="number">28</span>, <span class="number">25</span>]</span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h4 id="多系列柱状图"><a href="#多系列柱状图" class="headerlink" title="多系列柱状图"></a>多系列柱状图</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">data</span>: [<span class="string">&#x27;Mon&#x27;</span>, <span class="string">&#x27;Tue&#x27;</span>, <span class="string">&#x27;Wed&#x27;</span>, <span class="string">&#x27;Thu&#x27;</span>, <span class="string">&#x27;Fri&#x27;</span>, <span class="string">&#x27;Sat&#x27;</span>, <span class="string">&#x27;Sun&#x27;</span>]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">23</span>, <span class="number">24</span>, <span class="number">18</span>, <span class="number">25</span>, <span class="number">27</span>, <span class="number">28</span>, <span class="number">25</span>]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">26</span>, <span class="number">24</span>, <span class="number">18</span>, <span class="number">22</span>, <span class="number">23</span>, <span class="number">20</span>, <span class="number">27</span>]</span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h4 id="堆叠柱状图"><a href="#堆叠柱状图" class="headerlink" title="堆叠柱状图"></a>堆叠柱状图</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">data</span>: [<span class="string">&#x27;A&#x27;</span>, <span class="string">&#x27;B&#x27;</span>, <span class="string">&#x27;C&#x27;</span>, <span class="string">&#x27;D&#x27;</span>, <span class="string">&#x27;E&#x27;</span>]</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;&#125;,</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">10</span>, <span class="number">22</span>, <span class="number">28</span>, <span class="number">43</span>, <span class="number">49</span>],</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">stack</span>: <span class="string">&#x27;x&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">data</span>: [<span class="number">5</span>, <span class="number">4</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">10</span>],</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">stack</span>: <span class="string">&#x27;x&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h4 id="动态排序柱状图"><a href="#动态排序柱状图" class="headerlink" title="动态排序柱状图"></a>动态排序柱状图</h4><ol>
<li>柱状图系列的 <code>realtimeSort</code> 设为 <code>true</code>，表示开启该系列的动态排序效果</li>
<li><code>yAxis.inverse</code> 设为 <code>true</code>，表示 Y 轴从下往上是从小到大的排列</li>
<li><code>yAxis.animationDuration</code> 建议设为 <code>300</code>，表示第一次柱条排序动画的时长</li>
<li><code>yAxis.animationDurationUpdate</code> 建议设为 <code>300</code>，表示第一次后柱条排序动画的时长</li>
<li>如果想只显示前 <em>n</em> 名，将 <code>yAxis.max</code> 设为 <em>n - 1</em>，否则显示所有柱条</li>
<li><code>xAxis.max</code> 建议设为 <code>&#39;dataMax&#39;</code> 表示用数据的最大值作为 X 轴最大值，视觉效果更好</li>
<li>如果想要实时改变标签，需要将 <code>series.label.valueAnimation</code> 设为 <code>true</code></li>
<li><code>animationDuration</code> 设为 <code>0</code>，表示第一份数据不需要从 <code>0</code> 开始动画（如果希望从 <code>0</code> 开始则设为和 <code>animationDurationUpdate</code> 相同的值）</li>
<li><code>animationDurationUpdate</code> 建议设为 <code>3000</code> 表示每次更新动画时长，这一数值应与调用 <code>setOption</code> 改变数据的频率相同</li>
<li>以 <code>animationDurationUpdate</code> 的频率调用 <code>setInterval</code>，更新数据值，显示下一个时间点对应的柱条排序</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> data = [];</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; ++i) &#123;</span><br><span class="line">  data.<span class="title function_">push</span>(<span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>() * <span class="number">200</span>));</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">max</span>: <span class="string">&#x27;dataMax&#x27;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span>,</span><br><span class="line">    <span class="attr">data</span>: [<span class="string">&#x27;A&#x27;</span>, <span class="string">&#x27;B&#x27;</span>, <span class="string">&#x27;C&#x27;</span>, <span class="string">&#x27;D&#x27;</span>, <span class="string">&#x27;E&#x27;</span>],</span><br><span class="line">    <span class="attr">inverse</span>: <span class="literal">true</span>,</span><br><span class="line">    <span class="attr">animationDuration</span>: <span class="number">300</span>,</span><br><span class="line">    <span class="attr">animationDurationUpdate</span>: <span class="number">300</span>,</span><br><span class="line">    <span class="attr">max</span>: <span class="number">2</span> <span class="comment">// only the largest 3 bars will be displayed</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">realtimeSort</span>: <span class="literal">true</span>,</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;X&#x27;</span>,</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: data,</span><br><span class="line">      <span class="attr">label</span>: &#123;</span><br><span class="line">        <span class="attr">show</span>: <span class="literal">true</span>,</span><br><span class="line">        <span class="attr">position</span>: <span class="string">&#x27;right&#x27;</span>,</span><br><span class="line">        <span class="attr">valueAnimation</span>: <span class="literal">true</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">legend</span>: &#123;</span><br><span class="line">    <span class="attr">show</span>: <span class="literal">true</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">animationDuration</span>: <span class="number">3000</span>,</span><br><span class="line">  <span class="attr">animationDurationUpdate</span>: <span class="number">3000</span>,</span><br><span class="line">  <span class="attr">animationEasing</span>: <span class="string">&#x27;linear&#x27;</span>,</span><br><span class="line">  <span class="attr">animationEasingUpdate</span>: <span class="string">&#x27;linear&#x27;</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">update</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="keyword">var</span> data = option.<span class="property">series</span>[<span class="number">0</span>].<span class="property">data</span>;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; data.<span class="property">length</span>; ++i) &#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="title class_">Math</span>.<span class="title function_">random</span>() &gt; <span class="number">0.9</span>) &#123;</span><br><span class="line">      data[i] += <span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>() * <span class="number">2000</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      data[i] += <span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>() * <span class="number">200</span>);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  myChart.<span class="title function_">setOption</span>(option);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">setInterval</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="title function_">update</span>();</span><br><span class="line">&#125;, <span class="number">3000</span>);</span><br></pre></td></tr></table></figure>

<h4 id="阶梯瀑布图"><a href="#阶梯瀑布图" class="headerlink" title="阶梯瀑布图"></a>阶梯瀑布图</h4><p>Apache ECharts 中并没有单独的瀑布图类型，但是我们可以使用堆叠的柱状图模拟该效果。</p>
<p>假设数据数组中的值是表示对前一个值的增减：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">var data = [900, 345, 393, -108, -154, 135, 178, 286, -119, -361, -203];</span><br></pre></td></tr></table></figure>

<p>也就是第一个数据是 <code>900</code>，第二个数据 <code>345</code> 表示的是在 <code>900</code> 的基础上增加了 <code>345</code>……将这个数据展示为阶梯瀑布图时，我们可以使用三个系列：第一个是不可交互的透明系列，用来实现“悬空”的柱状图效果；第二个系列用来表示正数；第三个系列用来表示负数。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> data = [<span class="number">900</span>, <span class="number">345</span>, <span class="number">393</span>, -<span class="number">108</span>, -<span class="number">154</span>, <span class="number">135</span>, <span class="number">178</span>, <span class="number">286</span>, -<span class="number">119</span>, -<span class="number">361</span>, -<span class="number">203</span>];</span><br><span class="line"><span class="keyword">var</span> help = [];</span><br><span class="line"><span class="keyword">var</span> positive = [];</span><br><span class="line"><span class="keyword">var</span> negative = [];</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>, sum = <span class="number">0</span>; i &lt; data.<span class="property">length</span>; ++i) &#123;</span><br><span class="line">  <span class="keyword">if</span> (data[i] &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">    positive.<span class="title function_">push</span>(data[i]);</span><br><span class="line">    negative.<span class="title function_">push</span>(<span class="string">&#x27;-&#x27;</span>);</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    positive.<span class="title function_">push</span>(<span class="string">&#x27;-&#x27;</span>);</span><br><span class="line">    negative.<span class="title function_">push</span>(-data[i]);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">if</span> (i === <span class="number">0</span>) &#123;</span><br><span class="line">    help.<span class="title function_">push</span>(<span class="number">0</span>);</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    sum += data[i - <span class="number">1</span>];</span><br><span class="line">    <span class="keyword">if</span> (data[i] &lt; <span class="number">0</span>) &#123;</span><br><span class="line">      help.<span class="title function_">push</span>(sum + data[i]);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      help.<span class="title function_">push</span>(sum);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">option = &#123;</span><br><span class="line">  <span class="attr">title</span>: &#123;</span><br><span class="line">    <span class="attr">text</span>: <span class="string">&#x27;Waterfall&#x27;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">grid</span>: &#123;</span><br><span class="line">    <span class="attr">left</span>: <span class="string">&#x27;3%&#x27;</span>,</span><br><span class="line">    <span class="attr">right</span>: <span class="string">&#x27;4%&#x27;</span>,</span><br><span class="line">    <span class="attr">bottom</span>: <span class="string">&#x27;3%&#x27;</span>,</span><br><span class="line">    <span class="attr">containLabel</span>: <span class="literal">true</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">xAxis</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span>,</span><br><span class="line">    <span class="attr">splitLine</span>: &#123; <span class="attr">show</span>: <span class="literal">false</span> &#125;,</span><br><span class="line">    <span class="attr">data</span>: (<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">      <span class="keyword">var</span> list = [];</span><br><span class="line">      <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">1</span>; i &lt;= <span class="number">11</span>; i++) &#123;</span><br><span class="line">        list.<span class="title function_">push</span>(<span class="string">&#x27;Oct/&#x27;</span> + i);</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">return</span> list;</span><br><span class="line">    &#125;)()</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">yAxis</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&#x27;value&#x27;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">series</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">stack</span>: <span class="string">&#x27;all&#x27;</span>,</span><br><span class="line">      <span class="attr">itemStyle</span>: &#123;</span><br><span class="line">        <span class="attr">normal</span>: &#123;</span><br><span class="line">          <span class="attr">barBorderColor</span>: <span class="string">&#x27;rgba(0,0,0,0)&#x27;</span>,</span><br><span class="line">          <span class="attr">color</span>: <span class="string">&#x27;rgba(0,0,0,0)&#x27;</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="attr">emphasis</span>: &#123;</span><br><span class="line">          <span class="attr">barBorderColor</span>: <span class="string">&#x27;rgba(0,0,0,0)&#x27;</span>,</span><br><span class="line">          <span class="attr">color</span>: <span class="string">&#x27;rgba(0,0,0,0)&#x27;</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">data</span>: help</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;positive&#x27;</span>,</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">stack</span>: <span class="string">&#x27;all&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: positive</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">name</span>: <span class="string">&#x27;negative&#x27;</span>,</span><br><span class="line">      <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span><br><span class="line">      <span class="attr">stack</span>: <span class="string">&#x27;all&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: negative,</span><br><span class="line">      <span class="attr">itemStyle</span>: &#123;</span><br><span class="line">        <span class="attr">color</span>: <span class="string">&#x27;#f33&#x27;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h2 id="折线图"><a href="#折线图" class="headerlink" title="折线图"></a>折线图</h2><p>摆上去不太好看，最后试了一下就没再去管了</p>
<h1 id="Linux基本指令"><a href="#Linux基本指令" class="headerlink" title="Linux基本指令"></a>Linux基本指令</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">mkdir</span> -p a/b/c</span><br></pre></td></tr></table></figure>

<h1 id="Java基础Note"><a href="#Java基础Note" class="headerlink" title="Java基础Note"></a>Java基础Note</h1><p>Java中的Map是一种对键值对进行存储的数据结构。它提供了一种通过键快速查找和访问对应的值的方式，类似于字典或哈希表。</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://mvnrepository.com/artifact/com.mysql/mysql-connector-j">https://mvnrepository.com/artifact/com.mysql/mysql-connector-j</a></p>
<h2 id="Mysql-8-0处理"><a href="#Mysql-8-0处理" class="headerlink" title="Mysql 8.0处理"></a>Mysql 8.0处理</h2><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/morecccc/article/details/130497740">mysql8.0 报错Public Key Retrieval is not allowed</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.cnblogs.com/xiyixiaodao/p/13601854.html">Centos7安装MySQL8.0（RPM方式）</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.jianshu.com/p/224a891932d8">CentOS 7安装MySQL8.0</a></p>
<h1 id="补充资料"><a href="#补充资料" class="headerlink" title="补充资料"></a>补充资料</h1><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.zhihu.com/question/27974418/answer/38965760">如何用形象的比喻描述大数据的技术生态？Hadoop、Hive、Spark 之间是什么关系？</a></p>
<p>有了MapReduce，Tez和Spark之后，程序员发现，MapReduce的程序写起来真麻烦。他们希望简化这个过程。这就好比你有了汇编语言，虽然你几乎什么都能干了，但是你还是觉得繁琐。你希望有个更高层更抽象的语言层来描述算法和数据处理流程。于是就有了Pig和Hive。P<strong>ig是接近脚本方式去描述MapReduce，Hive则用的是SQL。它们把脚本和SQL语言翻译成MapReduce程序，丢给计算引擎去计算</strong>，而你就从繁琐的MapReduce程序中解脱出来，用更简单更直观的语言去写程序了。</p>
<p>除此之外，还有一些更特制的系统／组件，比如<strong>Mahout是分布式机器学习库</strong>，Protobuf是数据交换的编码和库，ZooKeeper是高一致性的<a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.zhihu.com/search?q=%E5%88%86%E5%B8%83%E5%AD%98%E5%8F%96%E5%8D%8F%E5%90%8C%E7%B3%BB%E7%BB%9F&search_source=Entity&hybrid_search_source=Entity&hybrid_search_extra=%7B%22sourceType%22:%22answer%22,%22sourceId%22:38965760%7D">分布存取协同系统</a>，等等。</p>
<p>作者：Xiaoyu Ma<br>链接：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.zhihu.com/question/27974418/answer/38965760">https://www.zhihu.com/question/27974418/answer/38965760</a><br>来源：知乎<br>著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://zhuanlan.zhihu.com/p/419504850">Hadoop 生态里，为什么 Hive 活下来了？</a></p>
<p>HDFS 被对象存储所取代，由 AWS S3 主导。MapReduce 已经被 Spark 所取代，Spark 也逐渐减少了对 Hadoop 的依赖性。Yarn 正在被像 Kubernetes 这样的技术取代。此外，Hive 的查询引擎组件在性能和采用方面已经被 <strong>Presto/Trino</strong> 超越。</p>
<p>Hive可以认为是MapReduce的一个包装，把好写的HQL转换为的MapReduce程序，本身不存储和计算数据，它完全依赖于HDFS和MapReduce，Hive中的表是纯逻辑表。hive需要用到hdfs存储文件，需要用到MapReduce计算框架</p>
<p>HBase：是一个Hadoop的数据库，一个分布式、可扩展、大数据的存储。hbase是物理表，不是逻辑表，<strong>提供一个超大的内存hash表</strong>，搜索引擎通过它来存储索引，方便查询操作。！！！</p>
<p>最开始是hadoop ，yarn+hdfs+mr全套的大数据处理系统，后来mr写起来太费事了，能不能简单点完成数据分析工作，就有了hive, sql化方式完成数据处理过程。再后来觉得觉得需要一个低延时查询东西，就有了hbase.</p>
<p>HDFS的具备存算一体的特性</p>
<p>但对象存储让存储与运算解耦</p>
<h2 id="数据大屏方案"><a href="#数据大屏方案" class="headerlink" title="数据大屏方案"></a>数据大屏方案</h2><p> <a target="_blank" rel="noopener external nofollow noreferrer" href="https://gitee.com/MTrun/vue-big-screen-plugin">vue-big-screen-plugin</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/gcpaas">科大国创</a></p>
<h2 id="MySQL拯救记录"><a href="#MySQL拯救记录" class="headerlink" title="MySQL拯救记录"></a>MySQL拯救记录</h2><p>帮别人配置环境时他们自己忘记初始密码了，去CSDN上找方案找解决方案</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_40757240/article/details/118068317">MySQL修改root用户密码</a></p>
<h2 id="Nohup使用"><a href="#Nohup使用" class="headerlink" title="Nohup使用"></a>Nohup使用</h2><p><code>nohup</code> 是 Linux 中的一个命令，用于在后台运行命令，并且忽略所有的挂起信号（SIGHUP）。该命令通常用于在登录会话结束时仍然继续运行进程。</p>
<p><code>nohup</code> 命令的使用方式如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">nohup</span> <span class="built_in">command</span> [options] [arguments] &amp;</span><br></pre></td></tr></table></figure>

<p>其中，<code>command</code> 是要在后台运行的命令，<code>options</code> 是命令的选项，<code>arguments</code> 是命令的参数。<code>&amp;</code> 符号用于将命令放到后台执行。</p>
<p>使用<code>nohup</code>命令后，命令的输出会被重定向到一个名为 <code>nohup.out</code> 的文件中。如果当前目录下已经存在 <code>nohup.out</code> 文件，则输出会追加到该文件中。如果不想产生 <code>nohup.out</code> 文件，可以将输出重定向到其他文件。</p>
<p>以下是一个使用 <code>nohup</code> 命令的示例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">nohup</span> ./myprogram -a -b &gt; output.log &amp;</span><br></pre></td></tr></table></figure>

<p>上述命令会在后台运行 <code>myprogram</code> 程序，并将程序的输出重定向到 <code>output.log</code> 文件中。同时，通过 <code>&amp;</code> 符号将命令放到后台执行。</p>
<p>使用 <code>nohup</code> 命令可以让命令在后台长时间运行，即使关闭终端或断开登录会话，进程也会继续执行。同时，输出文件 <code>nohup.out</code> 可以作为查看命令的输出和日志的便捷方式。</p>
<p>nohup的程序只能ps杀掉</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps aux | grep &lt;程序名称&gt;</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kill &lt;PID&gt;</span><br></pre></td></tr></table></figure>



<h2 id="Fedora-CoreOS"><a href="#Fedora-CoreOS" class="headerlink" title="Fedora-CoreOS"></a>Fedora-CoreOS</h2><p>详细经历可以看这里：</p>
<p><a href="https://www.mocusez.site/posts/9a9b.html">Fedora-CoreOS配置与试用（2023年）</a></p>
<h3 id="Butane"><a href="#Butane" class="headerlink" title="Butane"></a>Butane</h3><p>Butane (formerly the Fedora CoreOS Config Transpiler, FCCT) translates human readable Butane Configs into machine readable <a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/coreos/ignition">Ignition</a> Configs. See the <a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/coreos/butane/blob/main/docs/getting-started.md">getting started</a> guide for how to use Butane and the <a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/coreos/butane/blob/main/docs/specs.md">configuration specifications</a> for everything Butane configs support.</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/coreos/butane">https://github.com/coreos/butane</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://coreos.github.io/butane/specs/">https://coreos.github.io/butane/specs/</a></p>
<h3 id="使用Docker启动Hive"><a href="#使用Docker启动Hive" class="headerlink" title="使用Docker启动Hive"></a>使用Docker启动Hive</h3><p>3.1.3的官方镜像用不了，用的是4.0的alpha2</p>
<p>里面是derby数据库，且没有使用HDFS</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 10000:10000 -p 10002:10002 -p 50070:50070 --env SERVICE_NAME=hiveserver2 --name hive4 apache/hive:4.0.0-alpha-2</span><br></pre></td></tr></table></figure>



<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it hive4 beeline -u &#x27;jdbc:hive2://localhost:10000/&#x27;</span><br></pre></td></tr></table></figure>

<h2 id="RPM基本指令"><a href="#RPM基本指令" class="headerlink" title="RPM基本指令"></a>RPM基本指令</h2><h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -i package_name.rpm</span><br></pre></td></tr></table></figure>

<h3 id="卸载"><a href="#卸载" class="headerlink" title="卸载"></a>卸载</h3><p>要在CentOS中卸载软件包，可以按照以下步骤进行操作：</p>
<ol>
<li><p>使用以下命令来列出已安装的软件包：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep package_name</span><br></pre></td></tr></table></figure>
<p>将<code>package_name</code>替换为要卸载的软件包的名称。</p>
<p>或者，如果您知道软件包的详细名称，也可以使用以下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep -i <span class="string">&quot;detailed_package_name&quot;</span></span><br></pre></td></tr></table></figure>
<p>将<code>detailed_package_name</code>替换为要卸载的软件包的详细名称。</p>
</li>
<li><p>找到要卸载的软件包后，使用以下命令进行卸载：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo rpm -e package_name</span><br></pre></td></tr></table></figure>
<p>或者，如果您知道软件包的详细名称，可以使用以下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo rpm -e detailed_package_name</span><br></pre></td></tr></table></figure>
<p>上述命令将卸载指定的软件包。</p>
<p>注意：使用<code>rpm -e</code>命令卸载软件包时要非常小心，确保您选择正确的软件包。卸载软件包可能会导致其他软件包不可用或系统功能受损。</p>
</li>
<li><p>执行卸载命令后，系统可能会提示您输入<code>sudo</code>密码。输入密码后，按下<code>Enter</code>键继续卸载。</p>
</li>
<li><p>卸载完成后，系统将不再显示软件包的相关信息。</p>
</li>
</ol>
<p>请注意，有些软件包可能有其他的卸载方法，如使用<code>yum</code>命令。可以查阅软件包的官方文档或开发人员的指南，以获取更详细的卸载说明。</p>
<h3 id="更新"><a href="#更新" class="headerlink" title="更新"></a>更新</h3><p>升级</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum update</span><br></pre></td></tr></table></figure>

<p>升级整个CentOS系统：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum upgrade</span><br></pre></td></tr></table></figure>

<p>删除软件包：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum remove package_name</span><br></pre></td></tr></table></figure>



<h3 id="设置新的主机名"><a href="#设置新的主机名" class="headerlink" title="设置新的主机名"></a>设置新的主机名</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hostnamectl set-hostname new_hostname</span><br></pre></td></tr></table></figure>



<h2 id="hosts文件"><a href="#hosts文件" class="headerlink" title="hosts文件"></a>hosts文件</h2><p>Linux系统下修改/etc/hosts文件</p>
<h2 id="BI工具"><a href="#BI工具" class="headerlink" title="BI工具"></a>BI工具</h2><p>不少商业公司使用Business intelligence这样的系统做数据报表，其他不编程的小组就是采用这样的方案</p>
<p>Superset</p>
<p>DataEase</p>
<p>tablue</p>
<h2 id="LastDay"><a href="#LastDay" class="headerlink" title="LastDay"></a>LastDay</h2><p>我们小组选的是做西安高校的录取情况，下面记录的是SQL语句的调试情况（很多都是靠ChatGPT生成的doge）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> admission_year,category,college_name,enrolled_number</span><br><span class="line"><span class="keyword">FROM</span> shannxi_college_admission <span class="keyword">where</span> category<span class="operator">=</span>&quot;理工&quot; <span class="keyword">and</span> college_name<span class="operator">=</span>&quot;西安理工大学&quot;;</span><br></pre></td></tr></table></figure>



<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT sum(enrolled_number)</span><br><span class="line">FROM shannxi_college_admission where category=&quot;理工&quot; and college_name=&quot;西安理工大学&quot;;</span><br></pre></td></tr></table></figure>



<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> admission_year, college_name, <span class="built_in">sum</span>(enrolled_number) <span class="keyword">as</span> enrolled_number </span><br><span class="line"><span class="keyword">FROM</span> shannxi_college_admission </span><br><span class="line"><span class="keyword">WHERE</span> category<span class="operator">=</span>&quot;理工&quot; </span><br><span class="line"><span class="keyword">AND</span> admission_year <span class="keyword">BETWEEN</span> <span class="number">2015</span> <span class="keyword">and</span> <span class="number">2022</span></span><br><span class="line"><span class="keyword">AND</span> college_name <span class="keyword">IN</span> (&quot;西北农林科技大学&quot;, &quot;西北大学&quot;, &quot;西北工业大学&quot;, &quot;西北政法大学&quot;, &quot;西安交通大学&quot;, &quot;西安交通大学(医学部)&quot;, &quot;西安外国语大学&quot;, &quot;西安工业大学&quot;, &quot;西安工程大学&quot;, &quot;西安建筑科技大学&quot;, &quot;西安理工大学&quot;, &quot;西安电子科技大学&quot;, &quot;西安科技大学&quot;, &quot;西安邮电大学&quot;,&quot;陕西师范大学&quot;,&quot;陕西科技大学&quot;) </span><br><span class="line"><span class="keyword">GROUP</span> <span class="keyword">BY</span> admission_year, college_name;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h1 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h1><p>本轮生产实习为期10天，西安软件新城的伙食还不错。就是中午不睡觉有点顶不住，早上得在西安二环路上堵一个小时才能到实习地点，下午5点钟回学校只要30分钟。</p>
<p>最大的收获就是知道了什么是Hadoop，并且熟悉了Hive用法。感觉这种东西除非工作，平时是用不上这种东西的</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://www.mocusez.site">MocusEZ</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.mocusez.site/posts/5862.html">https://www.mocusez.site/posts/5862.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc/4.0" rel="external nofollow noreferrer" target="_blank">CC BY-NC 4.0</a> 许可协议。转载请注明来自 <a href="https://www.mocusez.site" target="_blank">Mox的笔记库</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2023/09/02/pPBH058.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/cd44.html"><img class="prev-cover" src="https://s1.ax1x.com/2023/09/08/pPyvO0O.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">JQuery的XSS初探</div></div></a></div><div class="next-post pull-right"><a href="/posts/9a9b.html"><img class="next-cover" src="https://s1.ax1x.com/2023/08/28/pPa8tlF.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Fedora-CoreOS配置与试用（2023年）</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="waline-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/head.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">MocusEZ</div><div class="author-info__description">探索未曾设想的道路</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">61</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/mocusez" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:285918468@qq.com" rel="external nofollow noreferrer" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="RSS"><i class="fas fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">迎接新的明天</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%94%9F%E4%BA%A7%E5%AE%9E%E4%B9%A0%E8%AE%B0%E5%BD%95"><span class="toc-number">1.</span> <span class="toc-text">生产实习记录</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Hadoop%E5%AD%A6%E4%B9%A0"><span class="toc-number">2.</span> <span class="toc-text">Hadoop学习</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Idea-Hadoop%E9%85%8D%E7%BD%AE"><span class="toc-number">2.1.</span> <span class="toc-text">Idea Hadoop配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HDFS%E6%8C%87%E4%BB%A4"><span class="toc-number">2.2.</span> <span class="toc-text">HDFS指令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#MapReduce%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="toc-number">2.3.</span> <span class="toc-text">MapReduce基本概念</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#MapReduce%E6%93%8D%E4%BD%9C"><span class="toc-number">3.</span> <span class="toc-text">MapReduce操作</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">3.1.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E5%AD%97%E5%9E%8B"><span class="toc-number">3.1.1.</span> <span class="toc-text">数字型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E5%9E%8B"><span class="toc-number">3.1.2.</span> <span class="toc-text">字符型</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Example"><span class="toc-number">3.2.</span> <span class="toc-text">Example</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Mapper"><span class="toc-number">3.2.1.</span> <span class="toc-text">Mapper</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Reducer"><span class="toc-number">3.2.2.</span> <span class="toc-text">Reducer</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Job%E5%AE%9E%E7%8E%B0"><span class="toc-number">3.2.3.</span> <span class="toc-text">Job实现</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%A7%E8%A1%8C%E7%A8%8B%E5%BA%8F"><span class="toc-number">3.2.4.</span> <span class="toc-text">执行程序</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Hive%E6%93%8D%E4%BD%9C"><span class="toc-number">4.</span> <span class="toc-text">Hive操作</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Beeline"><span class="toc-number">4.1.</span> <span class="toc-text">Beeline</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="toc-number">4.2.</span> <span class="toc-text">数据初始化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8"><span class="toc-number">4.3.</span> <span class="toc-text">启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#hiveserver2"><span class="toc-number">4.4.</span> <span class="toc-text">hiveserver2</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Metastore"><span class="toc-number">4.5.</span> <span class="toc-text">Metastore</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HiveQL"><span class="toc-number">4.6.</span> <span class="toc-text">HiveQL</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A1%A8%E5%88%9B%E5%BB%BA%E6%B5%8B%E8%AF%95"><span class="toc-number">4.6.1.</span> <span class="toc-text">表创建测试</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E5%BA%93"><span class="toc-number">4.6.2.</span> <span class="toc-text">删库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E8%A1%A8"><span class="toc-number">4.6.3.</span> <span class="toc-text">查看表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DML%E5%A4%84%E7%90%86"><span class="toc-number">4.6.4.</span> <span class="toc-text">DML处理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9E%E6%8E%A5JDBC"><span class="toc-number">4.6.5.</span> <span class="toc-text">连接JDBC</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#select%E6%93%8D%E4%BD%9C"><span class="toc-number">4.6.6.</span> <span class="toc-text">select操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Hive%E5%AE%9E%E7%8E%B0WordCount"><span class="toc-number">4.6.7.</span> <span class="toc-text">Hive实现WordCount</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B2%8C%E4%BC%BCDruid%E5%8F%AF%E4%BB%A5%E7%BB%9F%E4%B8%80MySQL%E4%B8%8EHive"><span class="toc-number">4.6.8.</span> <span class="toc-text">貌似Druid可以统一MySQL与Hive</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Druid"><span class="toc-number">4.7.</span> <span class="toc-text">Druid</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Sqoop"><span class="toc-number">4.8.</span> <span class="toc-text">Sqoop</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PyHive"><span class="toc-number">4.9.</span> <span class="toc-text">PyHive</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#insert-overwrite%E6%93%8D%E4%BD%9C"><span class="toc-number">4.10.</span> <span class="toc-text">insert overwrite操作</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Centos%E8%B8%A9%E5%9D%91"><span class="toc-number">5.</span> <span class="toc-text">Centos踩坑</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#ssh%E7%99%BB%E5%BD%95%E8%BF%87%E6%85%A2"><span class="toc-number">5.1.</span> <span class="toc-text">ssh登录过慢</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Themlef"><span class="toc-number">6.</span> <span class="toc-text">Themlef</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Layui"><span class="toc-number">6.1.</span> <span class="toc-text">Layui</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">6.2.</span> <span class="toc-text">启动配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%87%86%E8%A1%A8%E8%BE%BE%E5%BC%8F%E8%AF%AD%E6%B3%95"><span class="toc-number">6.3.</span> <span class="toc-text">准表达式语法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8Ejs%E7%BB%93%E5%90%88"><span class="toc-number">6.4.</span> <span class="toc-text">与js结合</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#th%E8%AF%AD%E6%B3%95"><span class="toc-number">6.5.</span> <span class="toc-text">th语法</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/3e9f.html" title="RMM观察与初探"><img src="https://z1.ax1x.com/2023/10/21/piF47TA.md.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="RMM观察与初探"/></a><div class="content"><a class="title" href="/posts/3e9f.html" title="RMM观察与初探">RMM观察与初探</a><time datetime="2023-10-21T04:30:00.000Z" title="发表于 2023-10-21 12:30:00">2023-10-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5e44.html" title="计算机网络课设——UDP/TCP/TLS Socket实验"><img src="https://s1.ax1x.com/2023/09/09/pP6qXOU.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="计算机网络课设——UDP/TCP/TLS Socket实验"/></a><div class="content"><a class="title" href="/posts/5e44.html" title="计算机网络课设——UDP/TCP/TLS Socket实验">计算机网络课设——UDP/TCP/TLS Socket实验</a><time datetime="2023-09-09T07:10:00.000Z" title="发表于 2023-09-09 15:10:00">2023-09-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/cd44.html" title="JQuery的XSS初探"><img src="https://s1.ax1x.com/2023/09/08/pPyvO0O.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JQuery的XSS初探"/></a><div class="content"><a class="title" href="/posts/cd44.html" title="JQuery的XSS初探">JQuery的XSS初探</a><time datetime="2023-09-08T04:30:00.000Z" title="发表于 2023-09-08 12:30:00">2023-09-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5862.html" title="生产实习记录"><img src="https://s1.ax1x.com/2023/09/02/pPBH058.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="生产实习记录"/></a><div class="content"><a class="title" href="/posts/5862.html" title="生产实习记录">生产实习记录</a><time datetime="2023-09-02T13:51:00.000Z" title="发表于 2023-09-02 21:51:00">2023-09-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/9a9b.html" title="Fedora-CoreOS配置与试用（2023年）"><img src="https://s1.ax1x.com/2023/08/28/pPa8tlF.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Fedora-CoreOS配置与试用（2023年）"/></a><div class="content"><a class="title" href="/posts/9a9b.html" title="Fedora-CoreOS配置与试用（2023年）">Fedora-CoreOS配置与试用（2023年）</a><time datetime="2023-08-28T11:35:00.000Z" title="发表于 2023-08-28 19:35:00">2023-08-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2023 By MocusEZ</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a href="http://beian.miit.gov.cn/" rel="external nofollow noreferrer"  style="color:#f72b07" target="_blank">闽ICP备2021003009号</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadWaline () {
  function insertCSS () {
    const link = document.createElement("link")
    link.rel = "stylesheet"
    link.href = "https://cdn.jsdelivr.net/npm/@waline/client/dist/waline.min.css"
    document.head.appendChild(link)
  }

  function initWaline () {
    const waline = Waline.init(Object.assign({
      el: '#waline-wrap',
      serverURL: 'https://waline.mocusez.site',
      pageview: ,
      dark: 'html[data-theme="dark"]',
      path: window.location.pathname,
      comment: false,
    }, null))
  }

  if (typeof Waline === 'function') initWaline()
  else {
    insertCSS()
    getScript('https://cdn.jsdelivr.net/npm/@waline/client/dist/waline.min.js').then(initWaline)
  }
}

if ('Waline' === 'Waline' || !false) {
  if (false) btf.loadComment(document.getElementById('waline-wrap'),loadWaline)
  else setTimeout(loadWaline, 0)
} else {
  function loadOtherComment () {
    loadWaline()
  }
}</script></div><script>(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/1df8ba05.js","daovoice")
</script><script>var isChatBtn = false
daovoice('init', {
  app_id: '1df8ba05',},{
  launcher: { 
     disableLauncherIcon: isChatBtn // 悬浮 ICON 是否显示
  },
});
daovoice('update');

if (isChatBtn) {
  var chatBtnFn = () => {
    var chatBtn = document.getElementById("chat_btn")
    chatBtn.addEventListener("click", function(){
      daovoice('show')
    });
  }
  chatBtnFn()
} else {
  if (false) {
    function chatBtnHide () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: true // 悬浮 ICON 是否显示
        },
      });
    }
    function chatBtnShow () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: false // 悬浮 ICON 是否显示
        },
      });
    }
  }
}</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>